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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1646 views
  • 3 likes
  • 5 in conversation