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?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.