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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 709 views
  • 0 likes
  • 2 in conversation