Hi!
I am trying to do a macro because I need a value for doing an array.
proc sql ;
select max(count(a,'#'))
into :max
from provisiones;
%put &max;
data test2 (drop=_: i);
set b ;
array a(%put &max;);
when I do the proc sql it´s okey and it returns me a number but when I run the next code it says that ERROR 22-322: Syntax error, expecting one of the following: una constante entera, *.
so my value in the proc sql doesn´t look like a constant. What can i do??
thanks in advance,
@anaroca12 Hi and welcome to the SAS Community 🙂
I assume that you want to compute some value in PROC SQL, save that in a macro variable and set up an array in a data step with the number of entries specified by that value.
If so, then use this as a template. Basically, just drop the %put statement from within the array definition.
proc sql noprint;
select max(age) into :max
from sashelp.class;
quit;
%put &max.;
data test;
set sashelp.class;
array a{&max.};
run;
@anaroca12 Hi and welcome to the SAS Community 🙂
I assume that you want to compute some value in PROC SQL, save that in a macro variable and set up an array in a data step with the number of entries specified by that value.
If so, then use this as a template. Basically, just drop the %put statement from within the array definition.
proc sql noprint;
select max(age) into :max
from sashelp.class;
quit;
%put &max.;
data test;
set sashelp.class;
array a{&max.};
run;
Yes, it´s perfect!! many thanks!! this was my first macro 🙂
@anaroca12 Cool stuff 🙂 I'm sure there are many more to come.
%put &max;
is just a macro statement that writes the value of &max to the log. Aside from that, it does nothing, and results in nothing. So your statement turns out to be
array a();
which is not valid syntax.
You need to simply use the macro variable:
array a(&max.);
For the usage of the dot, see Maxim 48.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.