BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User

The first thing the macro inserts in your code is a proc sql statement. That causes a step boundary for the data step, which has the unclosed do block at this moment, leading to the ERROR message.

I repeat: you cannot use this macro in a data step. But you can call it from the data step with call execute.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Aaargh, my eyes bleed from unformatted code shouted at me.  

Tom
Super User Tom
Super User

Just call the macro multiple times.

%U_Table(Cat_ID=70)
%U_Table(Cat_ID=79)

If your really need make the list of values dynamic then put them into a data step and use the data step to generate the code to call the macro.  So if you had a dataset with a variable named CAT_ID your could use with the CALL EXECUTE() function to generate one macro call for each observation.

data _null_;
  set category_list ;
  call execute(cats('%nrstr(%U_Table)(Cat_ID=',cat_id,')'));
run;
Deepankar
Calcite | Level 5

This worked. i don't want to run it separate as in your first example.

 

in the second example if you can confirm that macro is running one by one.

means value for 70 first then

value for 79 second.

 

how the loop is running here for two different value.

Tom
Super User Tom
Super User

@Deepankar wrote:

This worked. i don't want to run it separate as in your first example.

 

in the second example if you can confirm that macro is running one by one.

means value for 70 first then

value for 79 second.

 

how the loop is running here for two different value.


Yes.  It will call/execute the macro once for each value of CAT_ID.

 

If the macro uses the parameter value you passed in to create a table with a fixed name without producing any report or other output then calling it twice will just overwrite the first output with the second. However if the output table name is built dynamically from the parameter value passed in then you could call it twice and it would just create two different tables.

 

I did not look at the definition of the macro at all so I do not know if it can (or if it is even reasonable for to be able to ) handle more than one category code at a time.

 

Describe in words what the macro does and what output you want to create.  What is the meaning of the list of codes that you are starting with?  Do they represent separate things you want to do?  Or are they a set of categories that you want to group together somehow?

 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 19 replies
  • 3500 views
  • 0 likes
  • 6 in conversation