DATA Step, Macro, Functions and more

how to read mdyampm. dates (09/22/2015 20:15:32 AM)

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

how to read mdyampm. dates (09/22/2015 20:15:32 AM)

Hi

I have following  csv data

 

sample data:

id,created_date,modified_date

1021,12/23/2014 12:12:37 AM,9/21/2015 09:56:02 AM

1024,09/12/2015  04:24:00 PM,10/21/2015 11:44:03 AM

 

I have code:

 

DATA sample;

INFILE   '/path/file' dsd dlm=',' firstobs=2 ;

ATTRIB

id     informat = $5. format=$5.;

created_date   informat=mdyampm.  format=mdyampm.

modified_date  informat=mdyampm.  format=mdyampm. ;

INPUT id $ created_date Modified_date;

;run;

 

in My out put I am getting values for date variables like  9/21/2015 09:56:02 AM. 

How Can I get dates like 9/21/2015 21:56:02  or  datestamp (24 hours format without AM, PM). What is the right format I need to use for dates.

Thank you


Accepted Solutions
Solution
‎10-23-2015 08:45 PM
Respected Advisor
Posts: 3,889

Re: how to read mdyampm. dates (09/22/2015 20:15:32 AM)

[ Edited ]

All Replies
Solution
‎10-23-2015 08:45 PM
Respected Advisor
Posts: 3,889

Re: how to read mdyampm. dates (09/22/2015 20:15:32 AM)

[ Edited ]

If none of the OOTB formats is what you want..

http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0p2fmevfgj4...

 

...then you can always create your own picture format

http://support.sas.com/kb/24/621.html

 

Contributor
Posts: 40

Re: how to read mdyampm. dates (09/22/2015 20:15:32 AM)

Thank you for suggesting me PICTURE statement. Can we store customized date format in dataset?, I applied user defined format in PUT statement, PROC PRINT its working perfectly fine.

I have a dataset named Inventory as below:

Inv_no Record_dt
102 10Oct2015:14:00:00
103 12Oct2015:09:00:30

 

I tried with following code:

proc format;

picture limdate other='%0m/%0d/%0Y %0H:%0M:%0S' (datatype=datetime);

run;

 

data new_inv;

retain inv_no record_dt;

set inventory ;

format record_dt limdate.;

run;

 

but I am not successful.

so proc format Picture statement is only to display or presentation.???

Please suggest me if there is any way I can accomplish.

Thank you

 

Respected Advisor
Posts: 3,889

Re: how to read mdyampm. dates (09/22/2015 20:15:32 AM)

All formats are "for display only" and you can assign a picture format permanently to a variable like any other type of format.

 

If you assign a format permanenly (eg. with a format statement) to a permanent dataset then please be aware that you also need to store the format itself into a permanent catalog (or re-run the Proc Format at the beginning of a new session).

https://support.sas.com/documentation/cdl/en/proc/67916/HTML/default/viewer.htm#p0owakbeh7u19cn0zrqf...

 

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 264 views
  • 1 like
  • 2 in conversation