Sorry, this code doesnt work, but trying to sort the datetime variable
data have;
input datetime;
format datetime datetime.;
infile datalines missover;
datalines;
01AUG2022:11:51:35
22JUL2019:11:41:32
22JUL2019:11:50:32
25FEB2015:16:05:39
;
run;
try this input statement.
input datetime:datetime.;
That data step as shown will not generate any output data values to sort. Without a proper informat specified the input statement tells SAS to read the values as basic numeric values. But the : occurs as part of the value so is treated as not valid as a number.
586 data have; 587 input datetime; 588 format datetime datetime.; 589 infile datalines missover; 590 datalines; NOTE: Invalid data for datetime in line 591 1-18. RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-- 591 01AUG2022:11:51:35 datetime=. _ERROR_=1 _N_=1 NOTE: Invalid data for datetime in line 592 1-18. 592 22JUL2019:11:41:32 datetime=. _ERROR_=1 _N_=2 NOTE: Invalid data for datetime in line 593 1-18. 593 22JUL2019:11:50:32 datetime=. _ERROR_=1 _N_=3 NOTE: Invalid data for datetime in line 594 1-18. 594 25FEB2015:16:05:39 datetime=. _ERROR_=1 _N_=4 NOTE: The data set WORK.HAVE has 4 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
If you want the year to appear with 4 digits you need to set a longer than default width for the Datetime format.
data have; input datetime :datetime.; format datetime datetime19.; infile datalines missover; datalines; 01AUG2022:11:51:35 22JUL2019:11:41:32 22JUL2019:11:50:32 25FEB2015:16:05:39 ; run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.