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

Hi all

I tried to run the following macro

%macro q;

%do i=1 %to 69;

data verif&i ;

set D&&tabla.&i (obs=1000);

if &campo.&i = '0049';

%end;

run;

%mend q;

but whe the code runs I get the following text in the log

data verif45

set FFFFFF       45

if JJJJJJJ 45 = '0049'

How can I obtain the var FFFFF45 without spaces?. The same for var JJJJJ45.

Thanks in advanced

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Well, you don't say what the results are at this point.  But I think I can see from the program where you are going wrong.  These references do not properly identify your macro variables:

&tabla.&&i

&campo.&&i

Instead, you should be using:

&&tabla&i

&&campo&i

Notice that the dot in the middle should be removed.  Hope this takes care of it but if not, please describe what the results are.

View solution in original post

11 REPLIES 11
Reeza
Super User

Change how you're creating the macro variable so it doesn't have trailing spaces.

How are you creating it?

SYMPUTX automatically removes trailing spaces for example.

SergioSanchez
Calcite | Level 5

it´s a set of variables and I create them with

proc sql;

select tabla, campo

into :tabla1-:tabla69,

       :campo1-:campo69

from test;

quit;

Astounding
PROC Star

That SQL step would be the best place to remove extra blanks.  Replace:

select tabla, campo

Try this instead:

select strip(tabla), strip(campo)

There are a few ways to fix the problem later if you have to, but removing the blanks at the source is easy.

Good luck.

SergioSanchez
Calcite | Level 5

thanks Astounding but it doesn't work Smiley SadSmiley Sad

Here is the entire code:

proc sql;

select strip(tabla),strip(campo)

into  :tabla1-:tabla69,

       :campo1-:campo69

from test;

quit;

%macro entidad ;

%do i=1 %to 69;

data verif&i ;

set Dim.&tabla.&&i (obs=1000);

if &campo.&&i = '1012';

%end;

run;

%mend entidad;

What am I doing wrong?

Thanks

Astounding
PROC Star

Well, you don't say what the results are at this point.  But I think I can see from the program where you are going wrong.  These references do not properly identify your macro variables:

&tabla.&&i

&campo.&&i

Instead, you should be using:

&&tabla&i

&&campo&i

Notice that the dot in the middle should be removed.  Hope this takes care of it but if not, please describe what the results are.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

And you could do:

proc sql;

     create table LOOP as

     select strip(tabla),strip(campo)

     from test;

quit;

data _null_;

     call execute('data verif'||strip(put(_n_,best.))||';

                              set Dim.'||strip(table)||strip(put(_n_,best.))||' (obs=1000);

                              if '||strip(campo)||strip(put(_n_best.)||' = "1012";

                           run;');

run;

slchen
Lapis Lazuli | Level 10

There are blanks in the macro,try to use:%let tabla=&tabla; to remove tails blanks.

ballardw
Super User

It would help to show how your %tabla and %campo macro variables are created. I suspect a quoting or concatenation issue resulting in trailing blanks.

One fix might be before the data step:

let D&&dtabla.&I = %sysfunc(compress (D&&dtabla.&I); and similar for the Campo variable.

Ksharp
Super User

set D&&tabla.%left(&i) (obs=1000);

sachin01663
Obsidian | Level 7

As you are trying to attach string to a Macro, you have to use %left with Macro name. Try what Ksharp as said above and this code below

set Dim.&tabla.(%left&i) (obs=1000);

if &campo.(%left&i) = '1012';

%end;

run;

%mend entidad;

SergioSanchez
Calcite | Level 5

Hi all

it seems Astounding's option may work but I haven't access to the libname right now for testing

Thanks for your help

p.d: Works Fine, thanks all for your help Regards

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
  • 11 replies
  • 1392 views
  • 6 likes
  • 8 in conversation