I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

Reply
Contributor
Posts: 63

I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

%macro nam(inv);

data inc;

   set a.n_2;

   %if &inv. ge 0 %then %do; n_&inv=1; %end; %else %do;n_&inv=0 %end;

run;

%mend;

%nam(on_time_sub_new delayed_sub_new missed_sub_new scr_total_new

scr_part_new time_analytics_new time_assignment_new);

Trusted Advisor
Posts: 1,128

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

positional parameter(inv) value should be numeric, however you have given character value (on_time_sub_new delayed_sub_new missed_sub_new scr_total_newscr_part_new time_analytics_new time_assignment_new).

try some thing like numbers (0,1 etc., ) anything but it should be a number(numeric)

%nam(0);

Thanks,

Jagadish

Thanks,
Jag
Contributor
Posts: 63

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

The values in those variables are numeric.

Trusted Advisor
Posts: 1,128

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

I mean we need to pass the variable value.

Thanks,

Jagadish

Thanks,
Jag
Super Contributor
Posts: 333

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

I dont think the macro coding is doing what you think it is. Im guessing what you want is an array but not sure without more information.

It looks like to me when you are invoking the macro you are placing 7 variable names into the macro variable inv

on_time_sub_new

delayed_sub_new

missed_sub_new

scr_total_new

scr_part_new

time_analytics_new

time_assignment_new

So converting your macro code it turns into

  %if on_time_sub_new delayed_sub_new missed_sub_new scr_total_new scr_part_new time_analytics_new time_assignment_new

ge 0 %then %do; n_&inv=1; %end; %else %do;n_&inv=0 %end;


If the goal is to create 7 new variables prefix with n_ then the following should work without a macro:


data inc;

   set a.n_2;

     array old (7) on_time_sub_new  delayed_sub_new missed_sub_new scr_total_new scr_part_new time_analytics_new time_assignment_new;

     array new (7) n_on_time_sub_new  n_delayed_sub_new n_missed_sub_new n_scr_total_new

                         n_scr_part_new n_time_analytics_new n_time_assignment_new;

     do i = 1 to 7;

        if old(i) ge 0 then new(i)v=1;

          else new(i)=0

     end;

run;

Hope this helps!

EJ

Super Contributor
Posts: 282

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

Hi,

Please post the log showing your code and the error message so we can see where the error is being highlighted.

I think it would help us to understand what you want to achieve if you post the data step code that you expect to see generated from the macro call that you have shown.

Regards,

Amir.

Super User
Posts: 5,082

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

There are two problems.  First, there is a missing semicolon in the %ELSE result.  More important, you are generating illegal SAS code.  For example, what if &INV is -1?  Then you are trying to generate:

n_-1=0

n_-1 is not a legal variable name in SAS.  There are other possibilities, such as positive numbers that contain decimal fractions.  This statement would also be illegal:

n_3.14=1;

So you have to picture what the SAS code is supposed to look like as a first step.

Good luck.

Super User
Super User
Posts: 6,500

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

Note that macros just generate code that SAS will then process. You are passing in a space delimited list of variable names and then using them in a single generate assignment statement.  That could never work.

To process a number of variables you should use an ARRAY.  You can use macro logic to help with generating the names of the new variables.

%macro nam(varlist,inds=a.n_2,outds=inc);

data &outds;

   set &inds;

   array _old &varlist ;

   array _new N_%sysfunc(tranwrd(%sysfunc(compbl(&varlist)),%str( ),%str( N_))) ;

   do over _old;

     _new = (_old ge 0) ;

   end;

run;

%mend;

data test1;

  input x y;

cards;

1 2

-1 3

. 0

run;

options mprint;

%nam(x y,inds=test1,outds=test);

MPRINT(NAM):   data test;

MPRINT(NAM):   set test1;

MPRINT(NAM):   array _old x y ;

MPRINT(NAM):   array _new N_x N_y ;

MPRINT(NAM):   do over _old;

MPRINT(NAM):   _new = (_old ge 0) ;

MPRINT(NAM):   end;

MPRINT(NAM):   run;

Super Contributor
Posts: 333

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

Great solution Tom!  ... Always enjoy learning from your posts!

EJ

Contributor
Posts: 63

Re: I get the following error when running the below code. Not sure what is wrong. ERROR 180-322: Statement is not valid or it is used out of proper order

Thanks Tom.

Ask a Question
Discussion stats
  • 9 replies
  • 367 views
  • 2 likes
  • 6 in conversation