0
votes

I need a macro that will print out the "proc content" and the first 'k' observations of any dataset. Then I need it to further calculate some summary statistics of those first k observations such as mean, max, std and skewness. I'm familiar with SAS but I'm absolutely new to MACROS - to the point where documentation is confusing me.

I know in order to print out the first five variables you could use OBS and FIRSTOBS which I did in my previous work.

PROC PRINT DATA = WORK.CA(firstobs= 5 obs= 9);
RUN;

The same logic I can apply to summary statistics by using PROC MEANS by calculating std mean and so on. But how do I use a macro to make it applicable to any dataset?

1
I think your question is too broad. That being said, yours is a very simple case. Start by having fully working, tested code. Then create a macro variable that takes the data set name. Replace the data set reference everywhere with the macro variable. Once that's working, wrap it %macro/%mend. I highly recommend the SAS UCLA intro to macros.Reeza

1 Answers

1
votes
%macro MyMacro(data=,k=,var=);

proc contents data=&data varnum;
run;

proc print data=&data (obs=&k);
run;

proc means data=&data (obs=&k) mean max std skewness;
    var &var;
run;

%mend MyMacro;

%MyMacro(data=sashelp.class, k=10, var=Age Height Weight);