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!
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.
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.
Thanks for responding! The variable is numeric.
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.
Thanks! This was really helpful.
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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.