BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amng
Calcite | Level 5

Hi, I've recently downloaded a public data set for analysis, and they have some data in MMYYYY format. I would like to be able to use this data to understand the number of people that have received a service in the last 12 months. I think I need SAS to recognize the six numbers as a date, but am unsure how to do that.

 

It seems like I'll have to use proc format to create a format to do that - I've scoured the other message boards, but haven't found the exact answer to my problem.

 

Help appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Create a new variable that is an actual SAS date value. Then finding out how long it has been since the last service is easy mathematically. 

 

data want;
    set have;
    sasdate=input(put(date,6.),yymmn6.);
    format sasdate date7.;
run;

Then you could subtract this date from the date of the last  service, if the number is > 365, then no service in the last 12 months.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Is the variable that contains MMYYYY character or numeric?

 

You won't need PROC FORMAT, but I do need answer to the above question to know how to proceed.

--
Paige Miller
amng
Calcite | Level 5

Thanks for responding! The variable is numeric.

PaigeMiller
Diamond | Level 26

Create a new variable that is an actual SAS date value. Then finding out how long it has been since the last service is easy mathematically. 

 

data want;
    set have;
    sasdate=input(put(date,6.),yymmn6.);
    format sasdate date7.;
run;

Then you could subtract this date from the date of the last  service, if the number is > 365, then no service in the last 12 months.

--
Paige Miller
amng
Calcite | Level 5

Thanks! This was really helpful.

unison
Lapis Lazuli | Level 10

Adding onto @PaigeMiller 's response: you can take advantage of the INTNX function for the last part to avoid any issues with leap-years, etc. Assuming today is the comparison date for "within the last 12 months" and no future observations:

 

 

if intnx("month",sasdate,12,"s") ge today();

 or

 

 

if intnx("year",sasdate,1,"s") ge today();

 

Bringing the service date of the observation forward 12 months (or 1 year), is it greater than or equal to today's date?

-unison

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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