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

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

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

 

View solution in original post

7 REPLIES 7
Reeza
Super User

TRIMMED option

 

hhchenfx
Barite | Level 11

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.

Reeza
Super User

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. 

data_null__
Jade | Level 19
numeric to character conversion. right justified in a field 12 bytes long
hhchenfx
Barite | Level 11

So we can do Trim inside the SQL?

SASKiwi
PROC Star

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;

 

Ksharp
Super User
proc sql noprint; 
 select RR into: RR   separated by ' '
 from w;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 3493 views
  • 2 likes
  • 5 in conversation