Hi,
I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.
So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.
DATA file;
set file;
IF X1_1 in (1:3) & Y1_1>=70 & Y1_1<=100 then MI=1;
IF X2_1 in (1:3) & Y2_1>=70 & Y2_1<=100 then MI=1;
...
IF X10_1 in (1:3) & Y10_1>=70 & Y10_1<=100 then MI=1;
run;
I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.
You do not need a macro here, you need an array.
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
DATA file;
set file;
array x(*) x1_1--x10_1;*assumes variables are in order;
array y(*) y1_1 --y10_1;*assumes variables are in order;
*set to missing;
M1 = .;
do i=1 to 10 while(M1 ne 1);
if x(i) in (1:3) and y(i) >=70 and y(i) <= 100 then M1 =1;
end;
run;
@AmyH_01 wrote:
Hi,
I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.
So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.
DATA file;
set file;
IF X1_1 in (1:3) & Y1_1>=70 & Y1_1<=100 then MI=1;
IF X2_1 in (1:3) & Y2_1>=70 & Y2_1<=100 then MI=1;
...
IF X10_1 in (1:3) & Y10_1>=70 & Y10_1<=100 then MI=1;
run;
I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.
You do not need a macro here, you need an array.
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
DATA file;
set file;
array x(*) x1_1--x10_1;*assumes variables are in order;
array y(*) y1_1 --y10_1;*assumes variables are in order;
*set to missing;
M1 = .;
do i=1 to 10 while(M1 ne 1);
if x(i) in (1:3) and y(i) >=70 and y(i) <= 100 then M1 =1;
end;
run;
@AmyH_01 wrote:
Hi,
I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.
So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.
DATA file;
set file;
IF X1_1 in (1:3) & Y1_1>=70 & Y1_1<=100 then MI=1;
IF X2_1 in (1:3) & Y2_1>=70 & Y2_1<=100 then MI=1;
...
IF X10_1 in (1:3) & Y10_1>=70 & Y10_1<=100 then MI=1;
run;
I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.
I have just been @Reeza'd. Too fast.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.