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.
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!

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
  • 5 replies
  • 1950 views
  • 0 likes
  • 4 in conversation