BookmarkSubscribeRSS Feed
aparnaraju21150
Calcite | Level 5

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.

NOTE: Line generated by the macro variable "_CTRLNUM".
84 1000,2000,3000
____
18
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
Please suggest a new method or help me with this piece of code.
Thanks in advance.
4 REPLIES 4
Shmuel
Garnet | Level 18

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

 

aparnaraju21150
Calcite | Level 5

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.

Shmuel
Garnet | Level 18

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

PeterClemmensen
Tourmaline | Level 20

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;

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 852 views
  • 1 like
  • 3 in conversation