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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.