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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.
