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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1102 views
  • 1 like
  • 6 in conversation