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

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, 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

@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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

@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
Calcite | Level 5

Yes, it´s perfect!! many thanks!! this was my first macro 🙂

PeterClemmensen
Tourmaline | Level 20

@anaroca12 Cool stuff 🙂 I'm sure there are many more to come.

Kurt_Bremser
Super User
%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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1251 views
  • 3 likes
  • 3 in conversation