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

Hello:

 

I  have the following program.  I found the &N207 came with space and couldn't be recoganized.   How to remove the space of N207?  I have 200 macro N, I prefer not doing this one by one.  Thanks.

 

 

proc SQL;

 Select sum(case when find (name, 'nad_dx' )>0 then 1 else 0 end) into: N207 FROM &State.name;

quit;

 

data want;

set have (keep=nad_dx_&N207);

run;

 

SYMBOLGEN: Macro variable N207 resolves to                   32

ERROR: nad_dx_ does not have a numeric suffix.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

First thing is to not add the spaces to begin with use the TRIMMED keyword in the select. Or if you are running a really old version of SAS use SEPARATED BY  ' ' instead.

select count(*) into :N trimmed from ....

Second is add a step to re-assign the macro variable value to itself as this will remove leading/trailing spaces.

%let n=&n;

Or third since your value is an integer you can use %EVAL() where you reference the value.

data want;
  set have (keep=nad_dx_%eval(&N207));
run;

View solution in original post

9 REPLIES 9
Astounding
PROC Star

Either before or after the QUIT statement:

 

%let n207 = &n207;

 

This generates leading blanks to the right of the equal sign, but %LET ignores those leading blanks.

ybz12003
Rhodochrosite | Level 12

So if I have 207 macro N, could I do the following?  Or I have to list them one by one?

 

%let n1-n207 = &n201- &n207;

Astounding
PROC Star

If you have 207 macro variables, you probably got them by looping through 207 SELECT statements.  Just make the %LET statement part of the macro that contains the SELECT statement.  Since %LET can go before the QUIT statement that ends PROC SQL, this should be relatively straightforward but you can always post the macro if you need help with that.

ybz12003
Rhodochrosite | Level 12

Could you show me more details how to do it?  Thanks.

Astounding
PROC Star

If the SELECT statement is in a macro loop, it would look like this (in simplified form):

 

%do i=1 %to &n;

   select ... into : N&i;

%end;

 

If that's the case, you could always change that code to:

 

%do i=1 %to &n;

   select ... into : N&i;

   %let n&i = &&n&i;

%end;

 

Alternatively if you are just trying to handle 207 macro variables after the fact, embed this code in a macro:

 

%do i=1 %to 207;

   %let n&i = &&n&i;

%end;

 

This has to go inside a macro because %DO is not permitted outside of a macro.

  

Ksharp
Super User
Select sum(case when find (name, 'nad_dx' )>0 then 1 else 0 end) into: N207 separated by ' '
Tom
Super User Tom
Super User

First thing is to not add the spaces to begin with use the TRIMMED keyword in the select. Or if you are running a really old version of SAS use SEPARATED BY  ' ' instead.

select count(*) into :N trimmed from ....

Second is add a step to re-assign the macro variable value to itself as this will remove leading/trailing spaces.

%let n=&n;

Or third since your value is an integer you can use %EVAL() where you reference the value.

data want;
  set have (keep=nad_dx_%eval(&N207));
run;
ybz12003
Rhodochrosite | Level 12

Thanks for all of your great help.  I wish I could do multipul 'accept solution'.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 9 replies
  • 1319 views
  • 3 likes
  • 5 in conversation