Use MDY() to calculate the date. Use DOWNAME format to generate the name. Make sure to use the -L modifier or the LEFT() function as the ouptut of DOWNAME format is normally right aligned.
data want;
do year=2022 to 2023;
do month=1 to 12;
date=mdy(month,2,year);
format date date9.;
downame = put(date,downame.-L);
output;
end;
end;
run;
proc print;
run;
Obs year month date downame 1 2022 1 02JAN2022 Sunday 2 2022 2 02FEB2022 Wednesday 3 2022 3 02MAR2022 Wednesday 4 2022 4 02APR2022 Saturday 5 2022 5 02MAY2022 Monday 6 2022 6 02JUN2022 Thursday 7 2022 7 02JUL2022 Saturday 8 2022 8 02AUG2022 Tuesday 9 2022 9 02SEP2022 Friday 10 2022 10 02OCT2022 Sunday 11 2022 11 02NOV2022 Wednesday 12 2022 12 02DEC2022 Friday 13 2023 1 02JAN2023 Monday 14 2023 2 02FEB2023 Thursday 15 2023 3 02MAR2023 Thursday 16 2023 4 02APR2023 Sunday 17 2023 5 02MAY2023 Tuesday 18 2023 6 02JUN2023 Friday 19 2023 7 02JUL2023 Sunday 20 2023 8 02AUG2023 Wednesday 21 2023 9 02SEP2023 Saturday 22 2023 10 02OCT2023 Monday 23 2023 11 02NOV2023 Thursday 24 2023 12 02DEC2023 Saturday
data randomQuestion;
start = '02Jan2022'd;
do month=0 to 23;
date=intnx('month', start, month, 's');
weekday = put(date, downame.);
output;
end;
run;
Sunday/Wednesday/Wednesday/Saturday....added a format to see the months dates.
data randomQuestion;
start = '02Jan2022'd;
do month=0 to 23;
date=intnx('month', start, month, 's');
weekday = put(date, downame.);
output;
end;
format start date date9.;
run;
Use MDY() to calculate the date. Use DOWNAME format to generate the name. Make sure to use the -L modifier or the LEFT() function as the ouptut of DOWNAME format is normally right aligned.
data want;
do year=2022 to 2023;
do month=1 to 12;
date=mdy(month,2,year);
format date date9.;
downame = put(date,downame.-L);
output;
end;
end;
run;
proc print;
run;
Obs year month date downame 1 2022 1 02JAN2022 Sunday 2 2022 2 02FEB2022 Wednesday 3 2022 3 02MAR2022 Wednesday 4 2022 4 02APR2022 Saturday 5 2022 5 02MAY2022 Monday 6 2022 6 02JUN2022 Thursday 7 2022 7 02JUL2022 Saturday 8 2022 8 02AUG2022 Tuesday 9 2022 9 02SEP2022 Friday 10 2022 10 02OCT2022 Sunday 11 2022 11 02NOV2022 Wednesday 12 2022 12 02DEC2022 Friday 13 2023 1 02JAN2023 Monday 14 2023 2 02FEB2023 Thursday 15 2023 3 02MAR2023 Thursday 16 2023 4 02APR2023 Sunday 17 2023 5 02MAY2023 Tuesday 18 2023 6 02JUN2023 Friday 19 2023 7 02JUL2023 Sunday 20 2023 8 02AUG2023 Wednesday 21 2023 9 02SEP2023 Saturday 22 2023 10 02OCT2023 Monday 23 2023 11 02NOV2023 Thursday 24 2023 12 02DEC2023 Saturday
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.