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.
Aaargh, my eyes bleed from unformatted code shouted at me.
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;
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.
@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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.