[UseMoney=20]sas医学统计案例程序:差异检验 transpose ods html NPAR1WAY means freq gplot corr macro libname xls<br/>/*本程序都是我跑出来的,拥有 此程序可以让你sas 编程进步飞快<br/>可以登录我的msn查看更多的SAS CODE:<br/><!--Element not supported - Type: 8 Name: #comment--><a class="postlink" href="http://cid-7a2c11bd1414b988.spaces.live.com/blog/cns!7A2C11BD1414B988!208.entry">http://cid-7a2c11bd1414b988.spaces.live ... !208.entry</a><!--Element not supported - Type: 8 Name: #comment--><br/>*/<br/><br/>/*先导入每个表单:s1-对照组;s2-间重病例;s3-持重病例;<br/>s11-对照组人员背景;s12-对照组鼻塞,流涕,喷嚏,鼻痒,眼痒,流泪;<br/>s13-28个变量;s14-SF36中8个变量;<br/>SF-36量表。此量表共包括36个条目,分<br/>为8个维度,即生理功能(physical function,PF)、生理职能(re-<br/>sponsibility of physical,RP)、躯体疼痛(body pain,BP)、总体健<br/>康(general health,GH)、活力(vitality,VT)、社会功能(social<br/>function,SF)、情感职能(responsibility of emotion,RE)和精神<br/>健康(mental health,MH)<br/>*/<br/>options validvarname=any;<br/>%macro inputdata;/*导入三个表*/<br/>%do i=1 %to 3;<br/>%let ref="E:\lixin\q&i..xls";/**/<br/>libname lib &ref mixed=yes; *dbmax_text=50;/*虽然有mixed但是要保证exl前八个记录不能全是数值,而且不需要dbmax_text*/<br/>%do j=1 %to 4;/*办法二:LibName xlsLib "H:\ExcelToSas\Demo.xls" mixed=yes ;<br/>Missing M ;<br/>Data Sheet3( drop=_: ) ;<br/>Set xls."Sheet3$"n( reName=( x=_x y=_y ) ) ;<br/>x = input( _x , best. ) ;<br/>y = input( _y , best. ) ;<br/>Run ;<br/>LibName xls clear ;*/<br/>%let sheet="sheet&j$"n;<br/>data biyan.s&i&j;<br/>set lib.&sheet;<br/>run;<br/>%end;<br/>libname lib clear;<br/>%end;<br/>%mend ;<br/>%lixin;<br/>%macro setli;/*按表单合并,共4个*/<br/>%do i=1 %to 4;<br/>%let dui=s1&i;<br/>%let jian=s2&i;<br/>%let chi=s3&i;<br/>%put &dui;<br/>data su&i;<br/>*format class $ ;/*三个组别:对照 间重 持重*/<br/>set biyan.&dui(in=x) biyan.&jian(in=y) biyan.&chi(in=z);<br/>if x=1 then class='A'; /*if不需要加%*/<br/>if y=1 then class='B';<br/>if z=1 then class='C';<br/>run;<br/>%end;<br/>%mend inputdata;<br/>%inputdata;<br/><br/><br/>/*一,两样本或三样本差异检验:持重和间重<br/>在总体分布形式难确定或总体分布为偏态时,不适用T检验,故选用非参数统计方法。使用*/<br/>%macro NPA();/*title显示还有个问题:我想显示把表的名字也显示出来,改如何,因为这个结果看不出来是比较哪个表*/<br/>filename odsout 'e:\lixin\htmls';<br/>ods listing close;<br/>ods html body='CORR&NPA_mapbody.html'<br/>contents='CORR&NPA_contents.html'<br/>frame='相关分析和差异检验_frame.html'<br/>/*nogtitle*/<br/>path=odsout;<br/>/*nogtitle 添加此选项以后,可以自己定义目录名字,具体参考Gmap:Example 5*/<br/>%let title1="间重和持重";<br/>%let title2="对照和持重";<br/>%let title3="对照和间重";<br/>%do i=2 %to 4;<br/>%let s=su&i;<br/>%do j=1 %to 3;<br/>%if &j=1 %then %let zu='A' ; /*注意此处要两个let,而且if 在数据步外,所以要加%if*/<br/>%if &j=2 %then %let zu='B' ; <br/>%if &j=3 %then %let zu='C' ; <br/>/*不同组差异比较*/<br/>proc NPAR1WAY Wilcoxon anova DATA=&s(drop=编号);<br/>class class;<br/>where class^=&zu;<br/>title &&title&j 差异比较;<br/>output out=out;<br/>run;<br/><br/>/*同组相关分析*/<br/>proc corr data=&s(drop=编号) NOSIMPLE;<br/>where class=&zu;<br/>title COLOR=RED height=20pt &&title&j 相关分析;<br/>run;<br/>data plot;<br/>set out;<br/>n+1;<br/>keep _VAR_ PT2_WIL n;<br/>proc print ;/*找出差异显著的项*/<br/>where PT2_WIL<=0.05;<br/>title &&title&j 显著项;/*title可以不用连字符来连接字符串*/<br/>run;<br/>goptions reset=global gunit=pct border cback=white<br/>colors=(blue) htitle=4;<br/>symbol color=RED interpol=none width=2 value=dot height=1;<br/>axis1 label=( angle=90 height=3 "Two-sided P value") ;<br/><br/>proc gplot data=plot;<br/>plot PT2_WIL*_VAR_/vref=(0.05 0.01) vaxis=axis1; <br/>title &&title&j 显著项;<br/>run;<br/>quit;<br/>%end;<br/>%end;<br/>ods html close;<br/>ods listing;<br/>%mend;<br/>%NPA;<br/><br/><br/><br/>/*按性别组间检测*/<br/>%macro sex(zu);<br/>data sex;<br/>merge su1(keep=性别) su4 ;<br/>run;<br/>proc NPAR1WAY Wilcoxon anova DATA=sex ;<br/>class 性别; <br/>where class=&zu;title "&zu";/*宏在双引号才有效*/<br/>output out=wilsex;<br/>run;<br/>proc print data=wilsex;<br/>var PT2_WIL _VAR_;<br/>where PT2_WIL<=0.05;<br/>run;<br/><br/>%mend;<br/>%sex('C');/*参数可以改为B,A*/<br/><br/><br/><br/>%MACRO MEAN;<br/>filename odsout 'e:\lixin\htmls';<br/>ods listing close;<br/>ods html body='mean_mapbody.html'<br/>contents='mean_contents.html'<br/>frame='均值图.html'<br/>/*nogtitle*/<br/>path=odsout;<br/>%let title2="VAS";<br/>%let title3=" RQLQ";<br/>%let title4="SF-36";<br/>%do k=2 %to 4;<br/>%LET DATASET=su&k;<br/>proc means data=&dataset(drop=编号) maxdec=1 mean;/*maxdec=3设定均值小数位数*/<br/>class class;<br/>*title 'mean 求均值';<br/>output OUT=outmeans;<br/>title &&title&k 均值分析;<br/>run;<br/>data meansu2;<br/>set outmeans;<br/>if _type_=1 & _STAT_="MEAN";<br/>drop _type_ _freq_;<br/>run;<br/>PROC transpose data=meansu2 out=trans;<br/>by class;<br/>run;<br/>proc sort data=trans out=bymean;<br/>by _name_;<br/>run;<br/>data chart;<br/>set bymean;format col1 3.1;<br/>label _name_="症状" col1="均值";<br/>run;<br/>goptions reset=global colors=(red) ;<br/>pattern color=blue;<br/>title &&title&k 均值图;<br/>proc gchart data=chart;<br/>vbar3d class/discrete/*分组显示*/<br/>sumvar=col1<br/>inside=mean<br/>group=_NAME_;<br/>run;quit;<br/>%end;<br/>ods html close;<br/>ods listing;<br/>%MEND;<br/>%MEAN;<br/><br/>%macro top();/*RQLQ活动影响最大的*/<br/>filename odsout 'e:\lixin\htmls';<br/>ods listing close;<br/>ods html body='top_mapbody.html'<br/>contents='top_contents.html'<br/>frame='活动前三项.html'<br/>/*nogtitle*/<br/>path=odsout;<br/>data top;<br/>merge su1 su3;<br/>%do i=1 %to 3;<br/>act&i=compress(活动&i,,'ds');<br/>%end;<br/>keep 编号 class act1 act2 act3;/*1 活动2 活动3 活动1*/<br/>by class;<br/>run;<br/>data top1;<br/>set top;<br/>n+1;/*构建一个没有相同值的观察向量n*/<br/>select(class);<br/>when('A') 组别='对照';<br/>when('B') 组别='间重';<br/>when('C') 组别='持重';<br/>end;<br/>run;<br/>proc transpose data=top1 <br/>out=toptras(rename=(col1=活动));<br/>var act1-act3 ;/*将此三个变量合并为一列,需要一个没有相同值的向量n,*/<br/>by class n 组别 ;run;<br/><br/>proc freq data=toptras order=freq ;<br/>tables 活动*组别/NOCOL NOROW;<br/>*where class='B';<br/>title 'RQLQ活动影响排名' ;<br/>run;<br/>ods html close;<br/>ods listing;<br/>%mend;<br/>%top; <br/><script type="text/javascript"></script><script src="https://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><script></script><br/>[/UseMoney]
[此贴子已经被作者于2009-5-22 14:00:03编辑过]
<br>爱萌
金币 +5
魅力 +15
经验 +10
奖励公布了程序, 2009-5-21 0:42:15