Hi all,
I have a question on combining some data sets with macro. I have 4 tests and 12 grades. I would like to combine all of the grades for each relevant test. I don't get any error with the below code but it is taking only grade 12. Could you help me with what I am missing?
Thanks
%macro combine(k);
data &k._pl_all_n;
%do i=1 %to 12;
set pls_&k._gr_&i. ;
%end;
run;
%mend;
%combine(listening);
%combine(writing);
%combine(speaking);
%combine(reading);
You need a SET statement with a list of datasets, not a list of set statements where each overwrites the preceeding:
%macro combine(k);
data &k._pl_all_n;
set
%do i=1 %to 12;
pls_&k._gr_&i.
%end;
;
run;
%mend;
You need a SET statement with a list of datasets, not a list of set statements where each overwrites the preceeding:
%macro combine(k);
data &k._pl_all_n;
set
%do i=1 %to 12;
pls_&k._gr_&i.
%end;
;
run;
%mend;
Note that you could just as well use a dataset list:
%macro combine(k);
data &k._pl_all_n;
set pls_&k._gr_1 - pls_&k._gr_12;
run;
%mend;
Your macro creates these statements (SET is a statement, not a function!):
set pls_listening_gr_1;
set pls_listening_gr_2;
set pls_listening_gr_3;
set pls_listening_gr_4;
set pls_listening_gr_4;
set pls_listening_gr_5;
set pls_listening_gr_6;
set pls_listening_gr_7;
set pls_listening_gr_8;
set pls_listening_gr_9;
set pls_listening_gr_10;
set pls_listening_gr_11;
set pls_listening_gr_12;
so the data step reads an observation each from all 12 datasets (overwriting the PDV each time), and only the data from the last read remains to be written to the output dataset.
Move the SET statement out of the macro loop:
%macro combine(k);
data &k._pl_all_n;
set
%do i=1 %to 12;
pls_&k._gr_&i.
%end;
;
run;
%mend;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.