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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.