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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.