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

Hello all, I have the below code and would like to make it more concise. It could be macro, do-loop or other ways. Thank you in advance. 

 

data abc;

set abc;

date1 = intnx('day', start_date, 20);

date2 = intnx('day', date1, 20);

date3 = intnx('day', date2, 20);

date4 = intnx('day', date3, 20);

date5 = intnx('day', date4, 20);

date6 = intnx('day', date5, 20);

date7 = intnx('day', date6, 20);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data abc_new;

set abc;
array _dates(*) date1-date7;

do i=1 to dim(_dates);
    _dates(i) = intnx('day', start_date, 20*i);
end;

run;

Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 


@di_niu0 wrote:

Hello all, I have the below code and would like to make it more concise. It could be macro, do-loop or other ways. Thank you in advance. 

 

data abc;

set abc;

date1 = intnx('day', start_date, 20);

date2 = intnx('day', date1, 20);

date3 = intnx('day', date2, 20);

date4 = intnx('day', date3, 20);

date5 = intnx('day', date4, 20);

date6 = intnx('day', date5, 20);

date7 = intnx('day', date6, 20);

run;


 

View solution in original post

2 REPLIES 2
Reeza
Super User
data abc_new;

set abc;
array _dates(*) date1-date7;

do i=1 to dim(_dates);
    _dates(i) = intnx('day', start_date, 20*i);
end;

run;

Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 


@di_niu0 wrote:

Hello all, I have the below code and would like to make it more concise. It could be macro, do-loop or other ways. Thank you in advance. 

 

data abc;

set abc;

date1 = intnx('day', start_date, 20);

date2 = intnx('day', date1, 20);

date3 = intnx('day', date2, 20);

date4 = intnx('day', date3, 20);

date5 = intnx('day', date4, 20);

date6 = intnx('day', date5, 20);

date7 = intnx('day', date6, 20);

run;


 

di_niu0
Obsidian | Level 7
That's AMAZING. Thank you!!!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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