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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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