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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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