Hello, everyone. I am currently attempting to compute descriptive statistics, generate statistical plots and outputting them to datasets. My task is to perform these procedures on the very same variable using different grouping methods repetitively. I wish to use PROC UNIVARIATE to do the job, but the CLASS statement in PROC UNIVARITATE only accepts putting one variable in. Therefore, one way to achieve my goal is to write a code, copy that code and paste it somewhere else, change the variable name in the CLASS statement and the names of the output datasets, and do that job over and over again.
I think that method is a feasible yet somehow "dumb" one. Therefore, I tried to compose a SAS macro to help me deal with the problem. Please take a look at my code first:
data a;
input var$ @@;
cards;
aa ab ac ad ae af ag ah ai aj
;
run;
data b;
set c a;/*c is the dataset in which all of the data are stored*/
merge c a;
call symput ('i'||left(_n_),strip(var));
run;
%put _user_;
%macro st;
%do j=1 %to 10;
proc univariate data=b outtable=d&j. freq normal;
class i&j.;
var k;/*k is the variable I wish to analyze*/
ppplot;
cdfplot;
qqplot/normal(mu=est sigma=est);
output out=n&j. normaltest=n probn=p;
run;
%end;
%mend;
%st
The following code does not contain dataset printing/outputting arguments (e.g. PROC EXPORT), as error has already been reported during the process of running the aforementioned code.
The log said: "Variable Ix (x=1, 2, 3, ..., 7) unfound." So I think that the problem lies in the CLASS statement of the UNIVARIATE procedure of the SAS macro, since the initial names of the variables are aa, ab, ac, ad, ae, af, ag, ah, ai, aj; not i1, i2, ..., i7.
But before I run the macro, I have already used call symput and %put _user_ to "link" each and every one of the variables I input in dataset a with a macro variable whose prefix is i. SAS log also did not report any error of the "linking" process. The log was displayed as follows:
14 %put _user_;
GLOBAL I1 aa
GLOBAL I10
GLOBAL I100
...
GLOBAL I2 ab
...
GLOBAL I3 ac
...
/*Some of the logs were replaced with "..." manually for the sake of brevity*/
So, what is wrong with my code? How can I use SAS macro to achieve my goal I mentioned in the very beginning of my post?
Thank you!
... View more