BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
Hi
How to get every second day weekname in a month given date range
2022 to 2023 in this date range jan to december every month second day week name i want to get
Ex may 2nd 2023 is tuesday like that i want each month seconday week name
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

9 REPLIES 9
Reeza
Super User
So for July 2, 2023, you want the weekday name?
BrahmanandaRao
Lapis Lazuli | Level 10
Yes using loop every month second day week name
Reeza
Super User
data randomQuestion;
start = '02Jan2022'd;

do month=0 to 23;
    date=intnx('month', start, month, 's');
    weekday = put(date, downame.);
    output;
end;

run;
BrahmanandaRao
Lapis Lazuli | Level 10
Is it give weekname for each month 2022 to 2023
Reeza
Super User
What is a 'weekname'?
BrahmanandaRao
Lapis Lazuli | Level 10
What output you get
Reeza
Super User

Sunday/Wednesday/Wednesday/Saturday....added a format to see the months dates. 

 

Reeza_0-1682968912291.png

 

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;
BrahmanandaRao
Lapis Lazuli | Level 10
Thank you reeza for your support
Tom
Super User Tom
Super User

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

SAS Innovate 2025: Register Now

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!

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
  • 9 replies
  • 1105 views
  • 4 likes
  • 3 in conversation