BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
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

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Do you want the values in separate macro variables or in one macro variable?

s_lassen
Meteorite | Level 14

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 

andreas_lds
Jade | Level 19

Storing data in macro-variables almost always leads to unnecessary difficult code. So, because i am curious, what are the next steps?

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ballardw
Super User

@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-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1263 views
  • 1 like
  • 6 in conversation