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

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

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
Patrick
Opal | Level 21

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

 

nbonda
Obsidian | Level 7

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

 

Patrick
Opal | Level 21

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...

 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1766 views
  • 1 like
  • 2 in conversation