data a;
input name $ age height weight;
datalines;
don 28 168 76
;run;
%macro cols1; name age; %mend;
%macro cols2; height weight; %mend;
proc print data = a; var %cols2 %cols1; run;
Remove the semicolons and your code will work.
You normally only use macros for dynamic code generation.
For your case you'd rather use macro variables as in below sample code.
%let cols1=name age;
%let cols2=height weight;
proc print data = a;
var &cols2 &cols1;
run;
A macro definition for your sample could look like:
%macro doit(cols1,cols2);
proc print data = a;
var &cols2 &cols1;
run;
%mend;
%doit(name age, height weight);
And as an advice: Don't dive too early into SAS macro coding. First get "solid" with SAS data step and SAS Proc's.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.