BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

Hi all,

I'm facing an issue with the DateTime format and pleas find below the code 

 

{

DATA _TIME;
INFILE DATALINES;
INPUT CMS_DAT DATETIME26.;
FORMAT CMS_DAT DATETIME26.6;
CMS_DT = PUT(CMS_DAT,DATETIME30.6);
DATALINES;
22MAR2018:12:32:43.491538
06DEC2017:00:31:54.664700
03JAN2018:08:33:57.142454
17OCT2017:00:33:19.866942
2018-03-22-02.32.43.491538
28MAR2018:07:33:28.239593
;
RUN;
PROC PRINT DATA=_TIME;
RUN;

DATA _TIMEQ;
SET _TIME;
RESULT =TRIM(LEFT(PUT(DATEPART(CMS_DAT),YYMMDDD10.)||'-'||
PUT(TIMEPART(CMS_DAT),TIME15.6)));
RUN;
PROC PRINT DATA = _TIMEQ;
RUN;

}

 

and results are comming like 

RESULT

2018-03-22-12:32:43.491538
2017-12-06- 0:31:54.664700
2018-01-03- 8:33:57.142454
2017-10-17- 0:33:19.866942
.- .
2018-03-28- 7:33:28.239593

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

after datepart  all 0 values are missing 

so kindly help out this senioro 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

and my expecting results should be like

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

22MAR2018:12:32:43.491538
06DEC2017:(0)0:31:54.664700
03JAN2018:(0)8:33:57.142454
17OCT2017:(0)0:33:19.866942
.
28MAR2018:(0)7:33:28.239593

what ever i highleted with braghctes those are not comming in expexcted output

kindly give some solution for the above issue 

Thanks & regards 

rohit

 

 

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

You probably want the TOD format and not the TIME format to preserve the leading zero.

871   data _null_;
872     time='09:00't;
873     put 'TIME ' time time15.6;
874     put 'TOD  ' time tod15.6;
875   run;

TIME  9:00:00.000000
TOD  09:00:00.000000
rohitkrishna
Calcite | Level 5
Hi Tom KurtBremser
Thanks for the quick replay
it's working thanks very much
thanks & regards
rohit

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
  • 3 replies
  • 796 views
  • 0 likes
  • 3 in conversation