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
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
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.
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
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
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;
Thank you for your help, appreciate it!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.