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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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