BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

Hi all,

i'm facing sas DateTime function issue in my current job please find below the code 

 

{

     DATA _TIME;
INFILE DATALINES;
INPUT CMS_DAT $char30.;

CMS_DT = PUT(CMS_DAT, DATETIME30.6);
DATALINES;
22MAR2018:12:32:43.491538
06DEC2017:13:31:54.664700
03JAN2018:08:33:57.142454
17OCT2017:14:33:19.866942
28MAR2018:07:33:28.239593

run;

and my rec is : 2018-03-22-12.32.43.491538 

}

so kindly sugeust solution for above sas mainframe code 

& if i remove that put statment i'm getting sum other values after mention put statment it gving exact input values i'm not getting expecting results has mention on the colour 

thanks & regards 

rohit

 

 

12 REPLIES 12
Kurt_Bremser
Super User

Use the proper informat and format:

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:13:31:54.664700
03JAN2018:08:33:57.142454
17OCT2017:14:33:19.866942
28MAR2018:07:33:28.239593
; 

datetime values are numeric, read and handle them as such.

rohitkrishna
Calcite | Level 5
Hi Kurtbremser
thanks for the quick reply
{

CMS_DAT CMS_DT

22MAR2018:12:32:43.491538 22MAR2018:12:32:43.491538
06DEC2017:13:31:54.664700 06DEC2017:13:31:54.664700
03JAN2018:08:33:57.142454 03JAN2018:08:33:57.142454
17OCT2017:14:33:19.866942 17OCT2017:14:33:19.866942
. .
28MAR2018:07:33:28.239593 28MAR2018:07:33:28.239593

}

I'm getting above results are not exact results

i want my results should like: 2018-03-22-12.32.43.491538

thanks & regards
rohit
rohitkrishna
Calcite | Level 5
hi all
try to help out for the above problem
i want my results should be like

(2018-03-22-12.32.43.491538) I need output value,
not like
(22MAR2018:12:32:43.491538) this is an input value
thanks & regards
rohit
rohitkrishna
Calcite | Level 5

Hi all,

I required sum suggestion or solution for the below sas mainframe DateTime function job

 

(

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:13:31:54.664700
03JAN2018:08:33:57.142454
17OCT2017:14:33:19.866942
28MAR2018:07:33:28.239593
;
RUN;

 

                                                                                }

 

and I want my results should be like (2018-03-22-12:32:43.491538) expected results 

try to suggest some solution for the above sas code 

 

thanks & regards 

rohit

rohitkrishna
Calcite | Level 5
sorry results should be like
2018-03-22-12.32.43.491538
PaigeMiller
Diamond | Level 26

You could concatenate strings created by the YYMMDDx. format and the TIME. format.

--
Paige Miller
Kurt_Bremser
Super User

And here's an example of building a custom datetime format:

proc format library=work;
picture mydt
  low-high = '%Y-%0m-%0d-%0H.%0M.%0s' (datatype=datetime)
;
run;

data _time;
infile datalines;
input cms_dat datetime26.;
format cms_dat mydt26.6;
cms_dt = put(cms_dat,mydt26.6);
datalines;
22MAR2018:12:32:43.491538
06DEC2017:13:31:54.664700
03JAN2018:08:33:57.142454
17OCT2017:14:33:19.866942
28MAR2018:07:33:28.239593
;

proc print data=_time noobs;
run;

Result:

cms_dat                                 cms_dt

2018-03-22-12.32.43.491538    2018-03-22-12.32.43.491538
2017-12-06-13.31.54.664700    2017-12-06-13.31.54.664700
2018-01-03-08.33.57.142454    2018-01-03-08.33.57.142454
2017-10-17-14.33.19.866942    2017-10-17-14.33.19.866942
2018-03-28-07.33.28.239593    2018-03-28-07.33.28.239593
Kurt_Bremser
Super User

Please don't start multiple threads for the same question.

 

Since all standard formats use colons as separators in the time part, you will have to create a custom picture format with proc format.

 

Personally, I'd rather use the ISO 8601 international standard formats.

rohitkrishna
Calcite | Level 5
hi kurtbremser
I'm not getting you're point what you mention above statement
my requirement is to change the month
Jan to 01
Feb to 02 like that
remaining I can translate: to. I know that part but how to change this month is sum difficult to me
i use if condition for month change
if month = 'jan' then month = 01 like that
thanks & regards
rohit
Kurt_Bremser
Super User

We've already covered reading datetime strings with three-letter month names. To extract the month from the datetime value, use the datepart() and month() functions.

PaigeMiller
Diamond | Level 26

As implied by @Kurt_Bremser, you will not get where you want to go (or you will work very hard at it) unless you use the built-in SAS date and time functions (such as datepart and timepart) and date and time formats.

 

Here is an example that gets you the desired end result

 

data want;
	set _time;
	result = cats(put(datepart(cms_dat),yymmddd10.),'-',put(timepart(cms_dat),time18.6));
run;

 

 

--
Paige Miller
rohitkrishna
Calcite | Level 5
Hi KurtBremser, PaigeMiller
Thanks for the help it superb it's working
Thanks & regards
rohit

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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