Hi Everyone,
I use SQL to save macro value.
Some how when I use it in code, the value has space in front which return error.
proc sql noprint; select RR into: RR from w; quit;
%put "macro value:" &rr
...
keep type_RR&RR._sl
when &RR=3, the above code return these value. there is space in front.
In SAS log, that space appear to be a "tab" (big gap).
"macro value:" 3
Type_RR 3_sl
Can you please help me with that?
Thank you,
HHCFX
Yes, like this:
proc sql noprint;
select age into :age trimmed
from sashelp.class
where name = 'Mary'
;
quit;
%put age = &age;
Or you can use SQL functions to get the same result:
proc sql noprint;
select strip(put(age, 8.)) into :age
from sashelp.class
where name = 'Mary'
;
quit;
TRIMMED option
My trick is:
after the SQL to get macro variable RR, I put the code
%let RR=&RR;
so the problem is solved.
But so curious why that space come in the first place.
That's an extra step and a really old way to deal with it.
@hhchenfx wrote:
My trick is:
after the SQL to get macro variable RR, I put the code
%let RR=&RR;
so the problem is solved.
But so curious why that space come in the first place.
It's because macro variables are characters and you didn't specify a length so it assumed one and added spaces for it.
So we can do Trim inside the SQL?
Yes, like this:
proc sql noprint;
select age into :age trimmed
from sashelp.class
where name = 'Mary'
;
quit;
%put age = &age;
Or you can use SQL functions to get the same result:
proc sql noprint;
select strip(put(age, 8.)) into :age
from sashelp.class
where name = 'Mary'
;
quit;
proc sql noprint;
select RR into: RR separated by ' '
from w;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.