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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 535 views
  • 1 like
  • 2 in conversation