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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.