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

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