proc sql;
select name,sex,age into :n seperated by ', ' from sashelp.class
where name='William';
quit;
%put &=n. ;
%put &=a. ;
%put &=b. ;
I want name ,sex and age values in log window
Do you want the values in separate macro variables or in one macro variable?
I assume what you want is something like this:
proc sql noprint;
select name,sex,age into :n,:s,:a from sashelp.class
where name='William';
quit;
%put &=n. ;
%put &=a. ;
%put &=b. ;
I put in the NOPRINT option for the procedure, as I assume you do not want the print as well as the log lines.
The guide to SELECT ... INTO is here
Storing data in macro-variables almost always leads to unnecessary difficult code. So, because i am curious, what are the next steps?
@BrahmanandaRao wrote:
proc sql; select name,sex,age into :n seperated by ', ' from sashelp.class where name='William'; quit; %put &=n. ; %put &=a. ; %put &=b. ;
I want name ,sex and age values in log window
Others have given valuable advice.
Please, @BrahmanandaRao, from now on let's get the terminology correct so we can all avoid confusion. You are not talking about a "macro". You are talking about macro variables. Do not call macro variables by the name "macro". A macro is something different.
@BrahmanandaRao wrote:
proc sql; select name,sex,age into :n seperated by ', ' from sashelp.class where name='William'; quit; %put &=n. ; %put &=a. ; %put &=b. ;
I want name ,sex and age values in log window
data _null_; set sashelp.class; put name sex age; run;
SQL does not write much to the log. The data step Put statement will unless you provide a target File. Or use the PUTLOG statement to limit output to the log only.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.