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

Hi All, 

I have a dataset in csv format and I can import it to SAS data, but there is particular variable for date and time in the format of 200428202835 (which is YYMMDDHHMMSS). I wanted to read this variable as in proper format like date9. and time5. Is there any option to get above formatted date and time in this format. 

Best Regards,

Sairam 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way:

data example;
   x = '200428202835';
   date = input(x,yymmdd6.);
   time = input(substr(x,7), hhmmss.);
   format date date9. time time8.;
run;

You will likely need to read the value as character and then parse because this is a pretty non-typical format.

 

And talk to whoever is using 2 digit years. Did they not learn anything from Y2K?

View solution in original post

4 REPLIES 4
ballardw
Super User

One way:

data example;
   x = '200428202835';
   date = input(x,yymmdd6.);
   time = input(substr(x,7), hhmmss.);
   format date date9. time time8.;
run;

You will likely need to read the value as character and then parse because this is a pretty non-typical format.

 

And talk to whoever is using 2 digit years. Did they not learn anything from Y2K?

Sairampulipati
Fluorite | Level 6

Thank you very much for the resolution. I would reach to my data manager to check the Y2K. 

Tom
Super User Tom
Super User

@Sairampulipati wrote:

Thank you very much for the resolution. I would reach to my data manager to check the Y2K. 


If you can get the century digits included then your strings will match the B8601DJ informat.

https://documentation.sas.com/?docsetId=leforinforref&docsetTarget=n1hj2e5ozbucufn1laeoghx9pb6r.htm&...

FreelanceReinh
Jade | Level 19

Hi @Sairampulipati,

 

Assuming that you are using the most recommended technique for reading CSV files, a DATA step with INPUT statement(s), you can mix input styles and switch to formatted input for just the date part of this particular field.

 

Example:

data want;
infile cards dsd;
input seqno name $ date yymmdd6. time :hhmmss. amt :dollar.;
format date date9. time time8.;
cards;
1,John Doe,200428202835,$1234.56
;
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
  • 4 replies
  • 1539 views
  • 0 likes
  • 4 in conversation