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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 4 replies
  • 653 views
  • 3 likes
  • 3 in conversation