BookmarkSubscribeRSS Feed
kermit
Calcite | Level 5
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.
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 954 views
  • 0 likes
  • 2 in conversation