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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1125 views
  • 0 likes
  • 3 in conversation