SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cecillia_Mao
Obsidian | Level 7

Hi SAS experts, 

 

For the below codes, I don't understand why &varlist only catched “height”, and low only catched '1'. It supposed to be "height weight" for &varlist; and "1.0 25" for &lowlist. Any thoughts would be appreciated! 

 

Thanks in advance~

 

data a;
	input var $ low high;
	cards;
height 1.0 2.0
weight 25  200
;
run;
proc sql;
	select Var, low, high into:varlist,:lowlist,:highlist separated by ' '
	from a;
quit;
%put varlist: &varlist ---
	 lowlist: &lowlist ---
	 highlist:&highlist;

2020-08-11_000624.jpg 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Note that it does work for the last entry.

The portion of code " separated by ' ' " is only applied to the last set of items which is why that one shows correctly. Specify it for every list if you want to store multiple items in each list, otherwise it stores only the first value.

 

This works.

 

proc sql;
	select Var, low, high into
	:varlist separated by " ",
	:lowlist separated by " ",
	:highlist separated by ' '
	from a;
quit;
%put varlist: &varlist ---
	 lowlist: &lowlist ---
	 highlist:&highlist;

@Cecillia_Mao wrote:

Hi SAS experts, 

 

For the below codes, I don't understand why &varlist only catched “height”, and low only catched '1'. It supposed to be "height weight" for &varlist; and "1.0 25" for &lowlist. Any thoughts would be appreciated! 

 

Thanks in advance~

 

data a;
	input var $ low high;
	cards;
height 1.0 2.0
weight 25  200
;
run;
proc sql;
	select Var, low, high into:varlist,:lowlist,:highlist separated by ' '
	from a;
quit;
%put varlist: &varlist ---
	 lowlist: &lowlist ---
	 highlist:&highlist;

2020-08-11_000624.jpg 


 

View solution in original post

2 REPLIES 2
Reeza
Super User

Note that it does work for the last entry.

The portion of code " separated by ' ' " is only applied to the last set of items which is why that one shows correctly. Specify it for every list if you want to store multiple items in each list, otherwise it stores only the first value.

 

This works.

 

proc sql;
	select Var, low, high into
	:varlist separated by " ",
	:lowlist separated by " ",
	:highlist separated by ' '
	from a;
quit;
%put varlist: &varlist ---
	 lowlist: &lowlist ---
	 highlist:&highlist;

@Cecillia_Mao wrote:

Hi SAS experts, 

 

For the below codes, I don't understand why &varlist only catched “height”, and low only catched '1'. It supposed to be "height weight" for &varlist; and "1.0 25" for &lowlist. Any thoughts would be appreciated! 

 

Thanks in advance~

 

data a;
	input var $ low high;
	cards;
height 1.0 2.0
weight 25  200
;
run;
proc sql;
	select Var, low, high into:varlist,:lowlist,:highlist separated by ' '
	from a;
quit;
%put varlist: &varlist ---
	 lowlist: &lowlist ---
	 highlist:&highlist;

2020-08-11_000624.jpg 


 

Cecillia_Mao
Obsidian | Level 7
Thank you! That works perfectly!

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 2 replies
  • 942 views
  • 1 like
  • 2 in conversation