标题: 关于多个变量proc freq进行卡方检验的结果整理 [打印本页] 作者: shiyiming 时间: 2008-11-25 16:40 标题: 关于多个变量proc freq进行卡方检验的结果整理 在用proc freq进行卡放检验时,想把每个变量对应的p值的结果显示在同一个数据集里,发现output语句只能显示最后一个分析变量!于是想,是否可以一个变量一个output文件,然后再set呢,却发现少了一列变量名。如果在分析每个变量时,output的数据集里能够添加上文件名就好了,我的文件名是用所分析的变量命名的。但是却不知道如何能够为每个output的数据集添加一个变量名?
这样的做法可能不太好,但是能够解决问题。而且难免会有的数据集为空。不知道还有没有更好的方法?作者: shiyiming 时间: 2008-11-26 01:01 标题: Re: 如何在数据集中生成一个新变量,该变量的值为文件名? my 2 cents,
(1) you may use a dataset label to identify the table generated by the OUTPUT statement. if you want a new variable, you have to hard code it in a separate step;
(2) the OUTPUT statement may not be able to generate a dataset if some categories of your data are missing. if you add some zero-weighted observations for the missing categories and use the WEIGHT statement with ZEROS option, then there will always be a dataset.
As a computer slave, I do this a lot. The following is an example. It did slightly more than your needs because I transposed the frequency table before merging it horizontally with the p-value table. You sure can make the whole process a lot easier!
[code:3baztzel]
%macro draw_two_( dsn=,
outset=,
xvars=,
yvar=,
xcats=%str(0 1),
ycats=%str(0 1),
stat=%str(CHISQ|CHISQ|_PCHI_ P_PCHI)
);
%local i j k var;
%local N_xvar; %*# of X variables;
%local N_xcat; %*# of X categories;
%local N_ycat; %*# of Y categories;
%local stat_request
stat_out
stat_vars;
%let i=1;
%let var = %scan(&xvars, &i, %str( ));
%do %while(&var ne %str());
%local xvar&i;
%let xvar&i = %upcase(&var);
%let i=%eval(&i+1);
%let var = %scan(&xvars, &i, %str( ));
%end;
%let N_xvar=%eval(&i-1);
PROC CONTENTS DATA=&dsn OUT=&tmp1(KEEP=name type) NOPRINT;
PROC SQL NOPRINT;
SELECT type INTO :ytype
FROM &tmp1
WHERE upcase(name) = upcase("&yvar");
SELECT type INTO :xtype
FROM &tmp1
WHERE upcase(name) = upcase("&xvar1");
QUIT;
%*padding all combinations of &&xvar&i * &yvar w/ weight 0 to the input dataset;
DATA &tmp5;
SET &dsn(KEEP=&xvars &yvar) END=eof;
LENGTH wt 3;
RETAIN wt 1;
OUTPUT;
IF eof THEN DO;
wt = 0;
%do i=1 %to &N_xcat;
%do k=1 %to &N_xvar;
%if &xtype=1 %then %str(&&xvar&k = &&xcat&i;); %else %str(&&xvar&k = "&&xcat&i";);
%end; %*end of k=1 to # of x variables;
%do j=1 %to &N_ycat;
%if &ytype=1 %then %str(&yvar = &&ycat&j;); %else %str(&yvar = "&&ycat&j");
OUTPUT;
%end; %*end of j=1 to # of y categories;
%end; %*end of i=1 to # of x categories;
END;
RUN;