Hi all,
my dataset contains 2 numeric columns YEAR and MONTH. Example:
YEAR MONTH
2017 6
2018 8
2017 5
2019 11
I want to see a date of them (in SAS date format). It should looks like:
DATE
2017-06
2018-08
2017-05
2019-11
Have you any idea how to achieve that?
Have a nice day 🙂
Hi @PatrykSAS
You can do this.
-> the MDY() function returns a SAS date value from month, day, and year values.
-> DATE will be a valid SAS date, with a format to have the desired display
-> Here, the first of each month have been imputed.
Best,
data have;
input YEAR MONTH;
datalines;
2017 6
2018 8
2017 5
2019 11
;
run;
data want;
set have;
format DATE yymmd7.;
DATE = mdy(MONTH,1,YEAR);
run;
Do you want DATE to be a character or SAS Date variable?
data want;
set have;
date = mdy(month,1,year);
format date yymmd7.;
run;
Any SAS date must have a day of the month associated. SAS will use the first of the month as the day for the year and month only informats. So this would be consistent.
"Any SAS date must have a day of the month associated. SAS will use the first of the month as the day for the year and month only informats. So this would be consistent."
Good morning and Thank you Sir @ballardw for that. Those are valuable information/notes I am looking from veterans like you. Well, I often take notes in many of the threads you participate since the time you once taught me time series shifting intervals like fiscal- years/quarters. In essence, what I need is the mechanics of how stuff works, I shall do the coding myself. Thank you once again for all the notes that are priceless.
Hi @PatrykSAS
You can do this.
-> the MDY() function returns a SAS date value from month, day, and year values.
-> DATE will be a valid SAS date, with a format to have the desired display
-> Here, the first of each month have been imputed.
Best,
data have;
input YEAR MONTH;
datalines;
2017 6
2018 8
2017 5
2019 11
;
run;
data want;
set have;
format DATE yymmd7.;
DATE = mdy(MONTH,1,YEAR);
run;
Try this
data have;
input YEAR MONTH;
datalines;
2017 6
2018 8
2017 5
2019 11
;
data want;
set have;
date=mdy(month, 1, year);
format date yymmd7.;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.