Good day to everyone.
Got some issue with...idk even what type of problem is...macro, arrays or even do loop.
%macro name(indata=, some_num=);
data &indata_new;
set &indata;
array var_x_arr [*] var_x1 - var_x&some_num.;
array var_y_arr [*] var1_y - var&some_num._y;
do j = 1 to dim(var_x_arr);
if var_y_arr (j) = "Y" then do;
col4 = var_x_arr(j);
end;
end;
run;
%mend;
%name(indata=A, some_num=2);
%name(indata=B, some_num=5);
So, the essence of my question is that I have 2 types of variables that are always together (var_x1 and var1_y)
In dataset A there are only 2 of them (that is, var_x1 var1_y and var_x2 var2_y)
In dataset B there are only 5 of them (that is, var_x1 - var_x5 and, accordingly, var1_y - var5_y)
var_x1 accepts text values
var2_y accepts either 'Y' or 'N'
But it gives an error "ERROR: Missing numeric suffix on a numbered variable list (var_x1 - var_x2)
already triing "
array var_x_arr [&some_num.] var_x1 - var_x&some_num.;
array var_y_arr [&some_num.] var1_y - var&some_num._y;
do j = 1 to &some_num.; "
and different variants writing with these syntax( with $ and without, " to dim()" and so on)
My version is 9.4
You cannot make a variable list using syntax like:
var1_y - var5_y
The number must be at the END of the name.
The best thing would be to change your variable names. So something like:
var_y1 - var_y5
Otherwise you will need to use macro code to generate that goofy series of names.
array var_y_arr [*]
%do i=1 to &some_num;
var&i._y
%end;
;
So that you get this SAS code generated.
array var_y_arr [*] var1_y var2_y var3_y var4_y var5_y ;
You cannot make a variable list using syntax like:
var1_y - var5_y
The number must be at the END of the name.
The best thing would be to change your variable names. So something like:
var_y1 - var_y5
Otherwise you will need to use macro code to generate that goofy series of names.
array var_y_arr [*]
%do i=1 to &some_num;
var&i._y
%end;
;
So that you get this SAS code generated.
array var_y_arr [*] var1_y var2_y var3_y var4_y var5_y ;
Turn on the macro debugging tools by running this command
options mprint;
then run your macro again and show us the ENTIRE log (that's every single line, every single character, do NOT select just the error messages). Include the log in the window that appears when you click on the </> Icon. DO NOT SKIP THIS STEP.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.