Here is my question:
I want to using loop to repeat define step in proc report.
Here is my example:
*get data;
data mydata;
set sashelp.class;
run;
*rename the columns with regular name, like mycol1, mycol2...;
Store names and labels in a dataset, and use call execute() from that:
data columns;
input name label;
cards;
mycol1 title1
mycol2 title2
mycol3 title3
mycol4 title4
mycol5 title5
;
run;
data _null_;
set columns end=eof;
if _n_ = 1 then call execute('proc report data=finaldata;');
call execute('define ' !! name !! '/ "' !! trim(label) !! '";');
if eof then call execute('run;');
run;
You will probably expand the data _null_ step so that it also creates the column statement.
Thanks for your reply, Cynthia.
I want to write a macro to form a report dynamically with the header I provided.
In my case, I have many table to output. Every table have different header names.
for example, i have a table with 10 columns. If I want to generate a table with specific header manually, I have to write define ../.. 10 times. In addition, I have more than 30 tables like this to export. It is tedious and boring.
So I want to write a macro to deal with such problem.
Store names and labels in a dataset, and use call execute() from that:
data columns;
input name label;
cards;
mycol1 title1
mycol2 title2
mycol3 title3
mycol4 title4
mycol5 title5
;
run;
data _null_;
set columns end=eof;
if _n_ = 1 then call execute('proc report data=finaldata;');
call execute('define ' !! name !! '/ "' !! trim(label) !! '";');
if eof then call execute('run;');
run;
You will probably expand the data _null_ step so that it also creates the column statement.
Thank you KurtBremser.
Your mehod works.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.