Help using Base SAS procedures

SAS DATE- Last Available Day of Each Month

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

SAS DATE- Last Available Day of Each Month

Hi Guys,

I'm trying to retrieve from my data the last day (not calender day) of each month. However the last day may not be the last day of the calender month, but the last day of the month given my data.

Eg. 20080601

      20080627

      20080622

      20080712

      20080729

      20100128

      20100125

I am trying to get a code to retrieve 20080627, 20080729 and 20109128.

Thanks a lot guys!


Accepted Solutions
Solution
‎10-06-2012 02:46 PM
PROC Star
Posts: 7,492

Re: SAS DATE- Last Available Day of Each Month

You could do it easily with proc sql:

proc sql;

  create table want as

    select max(date) as last_day format date9.

      from have

        group by year(date),month(date)

  ;

quit;

View solution in original post


All Replies
Solution
‎10-06-2012 02:46 PM
PROC Star
Posts: 7,492

Re: SAS DATE- Last Available Day of Each Month

You could do it easily with proc sql:

proc sql;

  create table want as

    select max(date) as last_day format date9.

      from have

        group by year(date),month(date)

  ;

quit;

Contributor
Posts: 35

Re: SAS DATE- Last Available Day of Each Month

Hi Arthur,

Thanks for the code.

I was wondering if the date can be left in the original format YYYYMMDD. Because the code results in "2008 JAN 01" .

Thanks!

PROC Star
Posts: 7,492

Re: SAS DATE- Last Available Day of Each Month

just change the format from date9. to yymmddn8.

Super Contributor
Posts: 1,636

Re: SAS DATE- Last Available Day of Each Month

Hi Art,

yymmdd8. doesn't work for me. I changed it to yymmddn8. to get 20080828.  Thank you!

PROC Star
Posts: 7,492

Re: SAS DATE- Last Available Day of Each Month

Linlin: Then I will change mine as well.  As you can tell, it wasn't tested code.  Too busy listening to the Michigan State football game.

Super Contributor
Posts: 1,636

Re: SAS DATE- Last Available Day of Each Month

Hope they will win the game. I know you graduated there.Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 627 views
  • 0 likes
  • 3 in conversation