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
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.
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
You could concatenate strings created by the YYMMDDx. format and the TIME. format.
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
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.
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.