BookmarkSubscribeRSS Feed
jackwesley
Calcite | Level 5

 Hey there,

 

I need to convert a numeric in the format YY (e.g. '70' represents '1970') to a date format. I don't think I can use informats since I'm reading this in from a xls file.  Is there a straightforward way to do this? Whenever I try to use date formats, SAS assumes the values are already in SAS dat format and outputs 1960 for them all, because the values are all so small. I know this is a very basic question, but I'm brand new to SAS and after searching the internet I couldn't seem to find a suitable answer. Any help will be greatly appreciated.

Best,

 

Jack

4 REPLIES 4
mohamed_zaki
Barite | Level 11
data test;
input yy;
sasdate=mdy(1,1,yy);
format sasdate year.;
datalines;
70
;
run;
Astounding
PROC Star

I can't really think of a good reason to convert 60 to a date.  Why not just convert it to a year?  

 

Y = Y + 1900;

 

Easy to code, simple to interpret later.  

 

As was noted in the other response, if you do want to convert it to a date, you will have to pick which day of the year to use.  

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I completely agree with @Astounding, why bother converting when your just adding a number on.  However I would also add why are you using partial dates?  Should 10 be 1910 or 2010?  I would start by going back to the source and fixing the data there, you should never be guessing on what the data represents.

data_null__
Jade | Level 19

Also search at support.sas.com.  You will find the answer to most questions in the online documentation.

 

I do not agree that converting the year to a SAS date is a bad idea.  There are many reasons to use SAS dates that should be obvious to most.

 

@mohamed_zaki has answered your question and provide the formated needed to display '01JAN1970'd as a year.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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