BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tinaz5012
Obsidian | Level 7

Hi 

I am using the following code to read all values in column ccv_date_variabel into macro variables var1 - varn . 

proc sql noprint;
   select strip(CCV_date_variable) into : var1 - 
   from &SPEC;
quit;

The problem is there are some values are blank,  what I want is var1 has value blank and var2 has value "AESTDAT_RAW", but what I got is var1 equal to "AESTDAT_RAW". Could anyone please advise how can I solve this? thank you

screenshot.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

I agree with @Tom , but you can also do it this way:

data have;
length abc $ 10;
abc='';       output;
abc='azerty'; output;
abc='querty'; output;
run;
data _NULL;
 set have;
 call symput('var'!!strip(put(_N_,5.)),abc);
run;
%PUT &=var1; %PUT &=var2; %PUT &=var3;

Koen

View solution in original post

5 REPLIES 5
ballardw
Super User

You might provide just exactly how you intend to use that macro variable &var1.

How it is used would affect what the content should look like.

Tom
Super User Tom
Super User

I don't understand what you want that is different than what PROC SQL already generates.

data have;
  input x $10.;
cards;
 
ab
cd
 
ef
;
proc sql noprint;
 select x into :x1-  from have;
quit;

Results:

2405  %put &=sqlobs &=x1 &=x3 &=x5 ;
SQLOBS=5 X1= X3=cd X5=ef
2406  %put x1=%length(&x1) x2=%length(&x2);
x1=0 x2=2
sbxkoenk
SAS Super FREQ

Hello,

I agree with @Tom , but you can also do it this way:

data have;
length abc $ 10;
abc='';       output;
abc='azerty'; output;
abc='querty'; output;
run;
data _NULL;
 set have;
 call symput('var'!!strip(put(_N_,5.)),abc);
run;
%PUT &=var1; %PUT &=var2; %PUT &=var3;

Koen

Tom
Super User Tom
Super User

CALL SYMPUT() will allow you to include leading/trailing spaces in the generated macro variable.

 

So if you want the empty values generate a macro variable with exactly one space in it you need to use CALL SYMPUT() and also use TRIM(LEFT()) instead of STRIP() to preserve that single space.

data _null_;
  set &spec ;
  call symput(cats('var',_n_),trim(left(CCV_date_variable)));
run;

 

tinaz5012
Obsidian | Level 7

Thank you for your help, appreciate it!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1324 views
  • 0 likes
  • 4 in conversation