BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

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,

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

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

Steelers_In_DC
Barite | Level 11

Thanks so much.  That is exactly what I needed!

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1079 views
  • 0 likes
  • 2 in conversation