I am trying to generate two separate do loops within one macro. Anytime I get it to go through it goes like an array which I do not want. Without a macro the code looks like this:
data cus_hsd_&month1;
set cus_hsd_&month1;
format ver_start_day_key ver_end_day_key 8.;
ver_start_day_key= &lock1;
ver_end_day_key= &lock0;
run;
I have 18 of these which I'd like to do in one step, I want the start date to be separate from the end date (the last two lines) I'm not sure how to do that so I tried it with two do loops:
%macro ver_dates;
%do sd=1 %to 17;
data cus_hsd_&&month&sd;
set cus_hsd_&&month&sd;
format ver_start_day_key ver_end_day_key 8.;
ver_start_day_key = &&lock&sd;
%do ed=0 %to 16;
ver_end_day_key = &&lock&ed;
%end;
run;
%end;
%mend;
%ver_dates;
I've tried it many different ways, anytime it does work it's an array and the only date saved is the last date that ran. The first do loop runs through with every step, the last do loop runs at the very end and the last date is saved for every end_day_key.
Any help or suggestions will be appreciated. I'm not sure if I'm going about this the right way at all, just trying to neaten up some code in my spare time.
Thanks,
Hi,
try the modified code:
%macro ver_dates;
%do sd=1 %to 17;
data cus_hsd_&&month&sd;
set cus_hsd_&&month&sd;
format ver_start_day_key ver_end_day_key 8.;
ver_start_day_key = &&lock&sd;
%let ed=%eval(&sd-1);
ver_end_day_key = &&lock&ed;
run;
%end;
%mend;
%ver_dates
Linlin
Hi,
try the modified code:
%macro ver_dates;
%do sd=1 %to 17;
data cus_hsd_&&month&sd;
set cus_hsd_&&month&sd;
format ver_start_day_key ver_end_day_key 8.;
ver_start_day_key = &&lock&sd;
%let ed=%eval(&sd-1);
ver_end_day_key = &&lock&ed;
run;
%end;
%mend;
%ver_dates
Linlin
Thanks so much. That is exactly what I needed!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.