Hi All,
I am trying to create a table out of a macro variable which is having about 100 values,seperated by comma delimeter.
eg: %let _num = '10000,20000,30000....';
I tried the below piece of code:
%let _ctrlnum = '1000,2000,3000';
%LOCAL I;
DATA TEMP;
LENGTH CNTRLNUM $8.;
%do i=1 %to %sysfunc(countw(&_ctrlnum));
CNTRLNUM = "%scan(&_ctrlnum, &i)";
output;
%end;
run;
%mend generate;
%generate (CNTRLNUM = &_ctrlnum);
I am getting the following error:
ERROR: All positional parameters must precede keyword parameters.
A macro program should look like:
%macro <macro_name> (positional_argument(s) , named_argument= );
macro code, program code
%mend <macro_name>;
You either did not post all your code or miss the %macro statement.
Arguments to macro execution (%<macro_name> statement) should be written:
all positional arguments first in same order as defined in %macro statement then
named arguments in any order.
Therefore your next code line failed
%generate (CNTRLNUM = &_ctrlnum);
Hi Shmuel,
sorry, I didn't post the " %macro generate(CNTRLNUM=);"
The issue is the values in sas variable is being used from a front end for which the values may vary each time. So, I am not able to give the values in the code.
Can you please suggest any other way to create the table?
Thank You.
@aparnaraju21150 wrote:
Hi Shmuel,
sorry, I didn't post the " %macro generate(CNTRLNUM=);"
The issue is the values in sas variable is being used from a front end for which the values may vary each time. So, I am not able to give the values in the code.
Can you please suggest any other way to create the table?
Thank You.
According to error message:
ERROR: All positional parameters must precede keyword parameters.
===================================
there are some positional arguments defined before the cntrlnum= (named argument = keywors parameter),
i.e.
%macro generate( ? , ...?... ,CNTRLNUM=);
Check again the %macro line statement.
Hi and welcome to the SAS Community 🙂
You don't need a macro to do this
%let _ctrlnum = '1000,2000,3000';
data temp(drop=i);
length CNTRLNUM $8.;
do i=1 to countw(&_ctrlnum.);
CNTRLNUM=scan(&_ctrlnum., i, ',', '');
output;
end;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.