BookmarkSubscribeRSS Feed
Arun_shSAS
Fluorite | Level 6

 

%let C=test;



Data a;

input x $;

cards;

LI 

GI 

H&C

;



Proc sql noprint;

select x into: test2 separated by "," from a;

quit;

 

I want macro variable test2 to be resolved as LI,GI,H&C

 

3 REPLIES 3
Astounding
PROC Star
There will likely be headaches down the road, but you should be able to use %SUPERQ. For example:

%put %superq(test2);
Patrick
Opal | Level 21

@Arun_shSAS 

Looks like a case for %SUPERQ() or SYMGET().

%let C=test;

data a;
  input x $;
  cards;
LI 
GI 
H&C
;

proc sql noprint;
  select x into :test2 separated by "," from a;
quit;

%put Option_1: %superq(test2);

data _null_;
  Option_2=symget("test2");
  put Option_2=;
run;
Kurt_Bremser
Super User

The first question that comes to mind is "what for"?

Macro variables are the worst place for keeping data, SAS provides datasets as storage for that.

 

And if you need reference data for, say, where conditions, it's always better to use a defined key of some kind and not free-form text, which is the worst you can use for such things.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 520 views
  • 0 likes
  • 4 in conversation