BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

Would someone please let me know hw to convert this date to CCYYMMDD format.

Jun 31 2007 12:00AM

thanks,
sasbase9
5 REPLIES 5
GertNissen
Barite | Level 11
There is no such date as jun 31 !!

June only has 30 days 🙂
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
In a DATA step, you would use the appropriate INFORMAT with either an INPUT statement or INPUT function to parse the character string to a SAS numeric variable that represents a "date" (important for choosing your INFORMAT).

Then you must convert the "date" variable to be a "datetime" variable likely using the DHMS function - my preference.

Here's a general example that reads a date character string in a particular input format, converting to a date, and then assigning a new variable as a datetime:

DATA _NULL_;
format mydate date9. ;
INPUT mydate yymmdd8.;
format mydatetime datetime21. ;
mydatetime = dhms(mydate,0,0,0);
putlog _all_;
datalines
20090101
run;

The SAS support http://support.sas.com/ website has technical documentation and supplemental conference and sample papers on this type of topic - I have provided links below for reference.

Scott Barry
SBBWorks, Inc.


Dates, Times, and Intervals
About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm

Reading Raw Data
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001112330.htm

SAS 9.2 Language Reference: Dictionary - SAS INFORMATs and FORMATs are documented here:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/titlepage.htm
deleted_user
Not applicable
Hi,

Thanks SBB to reply back. I tried using below logic in my data set.

INPUT_VAR_DT_MM = PUT(month(PUT(input(var1,date9.),10.)),Z2.) ;


but it is not working. Our date on raw file is Like I said above , for ex : Nov 30 2008 12:08 AM.


Can you pls again let me know what needs to be corrected in my above logic.

thanks for help,
sasbase9
GertNissen
Barite | Level 11
Try [pre]
data test;
var1 = 'Nov 30 2008 12:08 AM';
INPUT_VAR_DT_MM = input(scan(var1,2)!!scan(var1,1)!!scan(var1,3), date9.);
put INPUT_VAR_DT_MM= INPUT_VAR_DT_MM= date.;
run;[/pre]
This will give you a SAS date (not datetime)!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Consider simplifying your code, for the "input" side - here is an example:

data _null_;
var1 = 'Nov 30 2008 12:08 AM';
format INPUT_VAR_DT_MM datetime. ;
INPUT_VAR_DT_MM = input(var1,anydtdtm.);
put _all_;
run;


Scott Barry
SBBWorks, Inc.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 839 views
  • 0 likes
  • 3 in conversation