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

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 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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;

 

 

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Do you want DATE to be a character or SAS Date variable?

PatrykSAS
Obsidian | Level 7
Date should be SAS date variable
ballardw
Super User

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.

novinosrin
Tourmaline | Level 20

"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. 

ed_sas_member
Meteorite | Level 14

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;

 

 

PatrykSAS
Obsidian | Level 7
It works great, thank you all
PeterClemmensen
Tourmaline | Level 20

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1215 views
  • 0 likes
  • 5 in conversation