Help using Base SAS procedures

converting dates - please help a novice

Reply
N/A
Posts: 1

converting dates - please help a novice

Hi there. I have a bunch of dates that I'm needing to subtract. When I imported the data from Excel, all of the dates were in the format of DATE9. except one (of course). This one annoying date is CHAR $8. Is there a *very* simple way to convert this date? I googled for solutions, and tried three different codes

1- new_var=input(old_var, yymmdd10.);
2- new_var=input(old_var, mmddyy9.);
3- new_var=input(old_var, DATE9.);

...but nothing's matching the format of the other vars (which in plain English, appear as DDMMMYYYY). Instead, the output shows all missing values with options 2 and 3. Option 1 results in a few of the dates converting properly, with the majority appearing as missing.

I'm so frustrated, and have a dissertation to finish! I'd be so grateful for any help.

Thanks so much in advance.
Super Contributor
Super Contributor
Posts: 3,174

Re: converting dates - please help a novice

Check the DOC and you will see that DATE9 is DDMMMYYYY format. Your code worked for me:

13 data _null_;
14 old_var = '01apr2010';
15 format new_var date9.;
16 new_var=input(old_var, DATE9.);
17 put _all_;
18 run;

old_var=01apr2010 new_var=01APR2010 _ERROR_=0 _N_=1
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 second


Also check the INFORMAT ANYDTDTE as well.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

converting dates site:sas.com
Ask a Question
Discussion stats
  • 1 reply
  • 102 views
  • 0 likes
  • 2 in conversation