BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kli
Calcite | Level 5 kli
Calcite | Level 5

Hello:

 

I have a column of csv data as following:

 

2020/09/11 02:14:27

2020/09/11 02:15:37

2020/09/11 02:16:08

 

During import SAS convert the column to Type Char instead of DATETIME.

 

How can I manually convert this column into SAS DATETIME format.

 

Thanks in advance,

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
Diamond | Level 26

Hi:

  If you use a DATA step program you can control how the variable is read and then deal with the date/time value as you wish. The ANYDTDTM informat allows you to read date/time values as you show in your example.

Cynthia_sas_0-1600795914364.png

 

Hope this helps,

Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
Diamond | Level 26

Hi:

  If you use a DATA step program you can control how the variable is read and then deal with the date/time value as you wish. The ANYDTDTM informat allows you to read date/time values as you show in your example.

Cynthia_sas_0-1600795914364.png

 

Hope this helps,

Cynthia

Tom
Super User Tom
Super User

CSV files are just text files. So there is no need to "import" them.  Just write a data step to READ the file instead. Then you have complete control over how each variable is defined.

data want;
  infile cards dsd ;
  input dt :anydtdtm. ;
  format dt datetime19.;
cards;
2020/09/11 02:14:27
2020/09/11 02:15:37
2020/09/11 02:16:08
;
Obs                     dt

 1      11SEP2020:02:14:27
 2      11SEP2020:02:15:37
 3      11SEP2020:02:16:08