BookmarkSubscribeRSS Feed
user112a2
Obsidian | Level 7

I have a question. I have a field in my SAS dataset that has a mixture of datetime and date variables.
The field is PST_DT and is Type: Numeric. Group: Date. Format: Date9. Length: 8.
Some values look like this:

Removed

How can I turn just the datetime values in date format? I want all the values to be in date format.
Thanks.

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

This does not look like a date9 formatted variable. Can you show a PROC CONTENTS output?

user112a2
Obsidian | Level 7

Removed

Kurt_Bremser
Super User

@user112a2 wrote:

I have a question. I have a field in my SAS dataset that has a mixture of datetime and date variables.
The field is PST_DT and is Type: Numeric. Group: Date. Format: Date9. Length: 8.
Some values look like this:

PST_DT
8/22/2018  11:59:59 PM
8/22/2018

How can I turn just the datetime values in date format? I want all the values to be in date format.
Thanks.


There's nothing at all that looks like a date9 formatted value.

Is your example actually a part of a text file you want to read into a SAS dataset?

user112a2
Obsidian | Level 7

These values were imported from an excel file into SAS. Some of the values had dates and some had datetime values. These were imported into a SAS data set. 

user112a2
Obsidian | Level 7

This worked!!!!

 

 

Removed
FreelanceReinh
Jade | Level 19

@user112a2 wrote:

This worked!!!!

 

 

data OUT.REQ_1_3_02 ;
SET OUT.REQ_1_3_01;

a= day(PST_DT);
b= month(PST_DT);
 c= year(PST_DT);
 date = input(catx("/",b,a,c),mmddyy10.);
 format date mmddyy10.;
run ;

Under normal circumstances, if PST_DT contains valid SAS date values or ordinary missing values, the four highlighted lines above could be simplified to:

date=PST_DT;