@Season wrote:
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.
Whenever you get errors in the log, please show us the ENTIRE log for the step that has the error. (not just the error messages, the ENTIRE log for the step that has the error). In this case, since the error is inside a macro, you need to run macro debugging option:
options mprint;
then run the code again and show us the ENTIRE log for the step that has the error.
Also, the best method to create macros is to first write code for one iteration without macro variables and without macros to get this to work. If you can't get it to work on one iteration without macro variables and without macros, you will never get a macro to work properly.
OK, thank you for your reminder. I will try CALL EXECUTE and see if there is still anything wrong.
@PaigeMiller wrote:options mprint;
By the way, where should I put these arguments? Should I place them here?
%macro st options mprint;
options mprint;
is a statement by itself, it should be placed before you run the macro.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.