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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1073 views
  • 0 likes
  • 2 in conversation