BookmarkSubscribeRSS Feed
igsteo
Calcite | Level 5

 

data fflib.Mnme_all;
  set fflib.me_all;
  if eod2=0 then set fflib.me_all (firstobs=2 keep=date rename=(date=nxt_date)) end=eod2;
  else nxt_date='31dec2030'd;
  if intck('month',date,nxt_date)>0;
run;

I wish to filter only December data. I am not sure what's the code for it and require some assistance. Thank you!

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Like this?

where month(DATE)=12;

mkeintz
PROC Star

You have a time series of data, and your current program captures the last value in each month. (BTW, I see "fflib" and some familiar variable names, is this fama-french data?).

 

By "I wish to filter only December data.", are you really only trying to get the last value in each year?  If so, then instead of 

 if intck('month',date,nxt_date)>0;

use

 if intck('year',date,nxt_date)>0;

Also you can use a MERGE statement to simplify your program instead of two SET statements (one conditional).  It's a bit neater.

data fflib.mnme_all:
  merge fflib.me_all
        fflib.me_all (firstobs=2 keep=date rename=(date=nxt_date));
  if intck('year',date,next_date)>0;
run;

But finally, your data appears to be monthly.  So (1) your filter eliminated no data, and (2) you can use @ChrisNZ 's suggestion to use a WHERE statement with the MONTH function:

data fflib.mnme_all:
  set fflib.me_all (where=(month(date)=12);
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1103 views
  • 0 likes
  • 3 in conversation