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

I have a date and time being sent to me in raw text format and I need to convert it to sas data format mmddyy10. I thought I could do this with a format statement, but not having much luck. Any help would be greatly appreciated.

 

data rawdata;       
input last_run_date $1-20;   
datalines;          
9-sep-2018 08:04:54 
9-sep-2018 08:01:41 
9-sep-2018 07:01:28 
9-sep-2018 05:06:23 
9-sep-2018 05:06:21 
31-oct-2017 14:56:35
31-oct-2017 11:08:46
31-oct-2017 10:17:21
31-may-2015 00:01:11
31-mar-2018 12:25:20
;                                     
                        

data want;

09/09/18

09/09/18

09/09/18

09/09/18

09/09/18

10/31/17

10/31/17

10/31/17

05/31/15

03/31/18

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If you use the proper informat when you read the data in, you get actual numeric SAS date time values, and then these can be displayed as mmddyy10.

 

data rawdata;        
    input last_run_date anydtdtm24.;
    date=datepart(last_run_date);
    format date mmddyy10.; 
datalines;           
...
;  

 

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

If you use the proper informat when you read the data in, you get actual numeric SAS date time values, and then these can be displayed as mmddyy10.

 

data rawdata;        
    input last_run_date anydtdtm24.;
    date=datepart(last_run_date);
    format date mmddyy10.; 
datalines;           
...
;  

 

 

--
Paige Miller
a079011
Obsidian | Level 7

Thank you! I was trying to convert after the fact. This is awesome thank you!!!

PaigeMiller
Diamond | Level 26

After the input, you can still do this

 

data rawdata;        
   input last_run_date $1-20;  
   date=datepart(input(last_run_date,anydtdtm24.));
   format date mmddyy10.;
   datalines;           
   ...
;  
--
Paige Miller
novinosrin
Tourmaline | Level 20

No need to read the time variable in the first place, like

data rawdata;        
input last_run_date  date11.;   
format last_run_date mmddyy10.; 
datalines;           
9-sep-2018 08:04:54  
9-sep-2018 08:01:41  
9-sep-2018 07:01:28  
9-sep-2018 05:06:23  
9-sep-2018 05:06:21  
31-oct-2017 14:56:35 
31-oct-2017 11:08:46 
31-oct-2017 10:17:21 
31-may-2015 00:01:11 
31-mar-2018 12:25:20 
;   

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 756 views
  • 0 likes
  • 3 in conversation