BookmarkSubscribeRSS Feed
SASlearner97
Obsidian | Level 7

I have a daily data 

date                  var        value

01/01/2013       a1          0

...

27/10/2020       a3         12

I want to get the data stored in the last day of each month for every year between the first date and the last date :

date                  var        value

31/01/2013      a1           5

28/02/2013      a2           4

.....

27/10/2020       a3         12

 

i thought of making a call symput of the dates but i dont know how to

 

please help

thank you

 

 

17 REPLIES 17
PaigeMiller
Diamond | Level 26

CALL SYMPUT has nothing to do with this. You need the INTNX function to get the last day of the month.

 

Something like this:

 

last_day_of_month=intnx('month',date,0,'e');
format last_day_of_month ddmmyys10.;

I don't understand why your input data doesn't match your output. In the Input data, your last value is 27/10/2020 while the output data has as its last value 30/09/2020.

--
Paige Miller
SASlearner97
Obsidian | Level 7
Thanks for your feedback

you are right i will edit the question;

actually i want to get the data stored in these dates ...
andreas_lds
Jade | Level 19

@SASlearner97 wrote:
Thanks for your feedback

you are right i will edit the question;

actually i want to get the data stored in these dates ...

Sorry, not clear what you mean with the last sentence. Please don't edit your initial post as this makes it impossible to understand all the answers given before the change.

SASlearner97
Obsidian | Level 7
i have a table of daily data

i want to select the data of only the end of months for each year

the ends of months maybe 28/03/2015
31/12/2015
30/04/2016 ..

PaigeMiller
Diamond | Level 26

@SASlearner97 wrote:
Thanks for your feedback

you are right i will edit the question;

actually i want to get the data stored in these dates ...

Now that you have edited the output data, the last value in the output data is NOT the last day of a month. Could you please explain?

--
Paige Miller
SASlearner97
Obsidian | Level 7
i have a table of daily data

i want to select the data of only the end of months for each year
PaigeMiller
Diamond | Level 26

@SASlearner97 wrote:

i want to select the data of only the end of months for each year

But your output (as modified by you earlier) doesn't do this. It shows 27/10/2020

--
Paige Miller
SASlearner97
Obsidian | Level 7
27/10/2020 is the last day of month in this example

thats why It shows 27/10/2020
andreas_lds
Jade | Level 19

@SASlearner97 wrote:
i have a table of daily data

i want to select the data of only the end of months for each year

So you want to select the all observations having date = max(date) by month/year?

SASlearner97
Obsidian | Level 7
yes
andreas_lds
Jade | Level 19

Try something like:

data bob;
  set have;
  group_date = intnx('MONTH', date, 0 'b');
run;

proc sort data=bob;
  by group_date date;
run;

data want;
  set bob;
  by group_date date;
  if last.date;
run;

If you want tested code, post data in usable form (data step with datalines, no attachments).

CurtisMackWSIPP
Lapis Lazuli | Level 10

You weren't clear about the environment in which you want to do this.  Does this come close?  The Macro could be eliminated.

 

%macro EOM(firstdata,lastdate);
  data dates;
    format date date9.;
    date = intnx("MONTH",input("&firstdata",date9.),0,"end");
    do until (date > input("&lastdate",date9.));
      output;
      date = intnx("MONTH",date,1,"end");
    end;
  run;
%mend;
%EOM(05JAN2020,14JUN2020);
SASlearner97
Obsidian | Level 7

yes it comes close

my table got some months that ends in 27 or less .. like i have 29/12/2011 for some var

how to find the ends of months of dates in my table please

Thank you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 1900 views
  • 3 likes
  • 6 in conversation