10-30-2013 12:48 AM
%if &inv. ge 0 %then %do; n_&inv=1; %end; %else %do;n_&inv=0 %end;
%nam(on_time_sub_new delayed_sub_new missed_sub_new scr_total_new
scr_part_new time_analytics_new time_assignment_new);
10-30-2013 01:23 AM
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)
10-30-2013 02:39 AM
The values in those variables are numeric.
10-30-2013 02:50 AM
I mean we need to pass the variable value.
10-30-2013 07:59 AM
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
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:
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;
Hope this helps!
10-30-2013 09:04 AM
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.
10-30-2013 09:32 AM
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 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:
So you have to picture what the SAS code is supposed to look like as a first step.
10-30-2013 09:56 AM
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.
array _old &varlist ;
array _new N_%sysfunc(tranwrd(%sysfunc(compbl(&varlist)),%str( ),%str( N_))) ;
do over _old;
_new = (_old ge 0) ;
input x y;
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) ;
10-30-2013 10:10 AM
Great solution Tom! ... Always enjoy learning from your posts!