繁体   English   中英

修改SAS宏以打印二分变量信息

[英]Modification of a SAS macro to print dichotomous variable information

我正在尝试修改以下SAS宏,以便当它等于0和1时都包括变量CHD的百分比。当前,此宏仅设置为在CHD(慢性)时打印出基线变量的结果。心脏病)等于1。我认为修改需要在data routfreq&i步骤中进行,但我不确定如何设置。 然后,我还需要另外一列以打印出“无冠心病*%(n)”。

%macro categ(pred,i);
 proc freq data = heart;
 tables &pred * chd / chisq sparse outpct out = outfreq&i ;
 output out = stats&i chisq;
 run;
 proc sort data = outfreq&i;
 by &pred;
 run;


proc means data = outfreq&i noprint;
 where chd ne . and &pred ne .;
 by &pred;
 var COUNT;
 output out=moutfreq&i(keep=&pred total rename=(&pred=variable)) sum=total;
 run;

data routfreq&i(rename = (&pred = variable));
 set outfreq&i;
 length varname $20.;
if chd = 1 and &pred ne .;
rcount = put(count,8.);
 rcount = "(" || trim(left(rcount)) || ")";
 pctnum = round(pct_row,0.1) || " " || (rcount);
index = &i;
 varname = vlabel(&pred);
 keep &pred pctnum index varname;
 run;

data rstats&i;
 set stats&i;
 length p_value $8.;
 if P_PCHI <= 0.05 then do;
 p_value = round(P_PCHI,0.0001) || "*";
 if P_PCHI < 0.0001 then p_value = "<0.0001" || "*";
 end;
 else p_value = put(P_PCHI,8.4);
 keep p_value index;
 index = &i;
 run;


data _null_;
 set heart;
 call symput("fmt",vformat(&pred));
run;

proc sort data = moutfreq&i;
 by variable;
 run;
 proc sort data = routfreq&i;
 by variable;
 run;
 data temp&i;
 merge moutfreq&i routfreq&i;
 by variable;
 run;

data final&i;
 merge temp&i rstats&i;
 by index;
 length formats $20.;
 formats=put(variable,&fmt);
 if not first.index then do;
varname = " ";
p_value = " ";
 end;
 drop variable;
 run;
%mend;


%categ(gender,1);
%categ(smoke,2);
%categ(age_group,3);

%macro names(j,k,dataname);
 %do i=&j %to &k;
 &dataname&i
 %end;
 %mend names;

data categ_chd;
 set %names(1,3,final);
 label varname = "Demographic Characteristic"
 total = "Total"
pctnum = "Coronary Heart Disease * % (n)"
 p_value = "p-value * (2 sided)"
formats = "Category";
 run;

ods listing close;
ods rtf file = "c:\nesug\table1a.rtf" style = forNESUG;
proc report data = categ_chd nowd split = "*";
 column index varname formats total pctnum p_value;
 define index /group noprint;
compute before index;
 line ' ';
endcomp;
 define varname / order = data style(column) = [just=left] width = 40;
 define formats / order = data style(column) = [just=left];
 define total / order = data style(column) = [just=center];
 define pctnum / order = data style(column) = [just=center];
 define p_value / order = data style(column) = [just=center];
 title1 " NESUG PRESENTATION: TABLE 1A (NESUG 2004)";
 title2 " CROSSTABS OF CATEGORICAL VARIABLES WITH CORONARY HEART DISEASE OUTCOME";
run;
ods rtf close;
ods listing; 

另外,此代码在运行时具有以下错误:

NOTE: PROCEDURE MEANS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      1:2
NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      3:111

我认为此宏需要进行修改,以使其在使用分类/字符变量运行时不会崩溃。

线

if chd = 1 and &pred ne .;

是什么导致您的输出仅具有CHD =“ 1”。您将其更改为:

if chd = 1 and &pred ne .;

我不明白您要求增加一栏。 也许发布当前输出和所需输出的示例?

至于“错误”(实际上要注意,因为它们不会导致系统停止处理),是在变量自动从数字转换为字符或反之时发生的。 它提供代码行发生的位置以及发生的次数。 我希望尽可能多地消除这些注意事项,以免因不当的胁迫而产生意想不到的后果。 为此,您将使用PUT和INPUT功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM