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
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.
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.
it´s a set of variables and I create them with
proc sql;
select tabla, campo
into :tabla1-:tabla69,
:campo1-:campo69
from test;
quit;
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.
thanks Astounding but it doesn't work
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
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.
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;
There are blanks in the macro,try to use:%let tabla=&tabla; to remove tails blanks.
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.
set D&&tabla.%left(&i) (obs=1000);
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;
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
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.