BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I want to create data set by enter the data.

What is the way to define the informat for data set "Have1"?

Note- Informat for data set "Have2" is working well

 

data have1;
input d_time : datetime18.;
format d_time datetime20.;
cards;
27/05/2023:06:05:00
03/10/2022:14:24:00
02/10/2022:20:19:00
;
Run;

data have2;
input d_time : datetime18.;
format d_time datetime20.;
cards;
27MAY2023:06:05:00
03OCT2022:14:24:00
02OCT2022:20:19:00
;
Run;
3 REPLIES 3
PaigeMiller
Diamond | Level 26

What is wrong with your code? Please explain. If there are problems in the log, show us the ENTIRE log (not the first time we have asked). If the output is wrong, tell us in words what you are seeing that is incorrect.

--
Paige Miller
Tom
Super User Tom
Super User

You could try the ANYDTDTM informat.

678  data have1;
679  input d_time : anydtdtm.;
680  format d_time datetime20.;
681  put d_time _infile_;
682  cards;

27MAY2023:06:05:00 27/05/2023:06:05:00
10MAR2022:14:24:00 03/10/2022:14:24:00
10FEB2022:20:19:00 02/10/2022:20:19:00
NOTE: The data set WORK.HAVE1 has 3 observations and 1 variables.

But  you will notice that for the ambiguous records where the first value could be either the month or the day of the month (at least on my machine) it defaults to use MDY ordering.

 

If you want to force it to use DMY order in those ambiguous situations then you need to se the datestyle option.

690  options datestyle=dmy;
691  data have1;
692  input d_time : anydtdtm.;
693  format d_time datetime20.;
694  put d_time _infile_;
695  cards;

27MAY2023:06:05:00 27/05/2023:06:05:00
03OCT2022:14:24:00 03/10/2022:14:24:00
02OCT2022:20:19:00 02/10/2022:20:19:00
NOTE: The data set WORK.HAVE1 has 3 observations and 1 variables.
Kurt_Bremser
Super User
data have1;
input d ddmmyy10. @12 t time8.;
d_time = dhms(d,0,0,t);
format d_time datetime20.;
drop d t;
cards;
27/05/2023:06:05:00
03/10/2022:14:24:00
02/10/2022:20:19:00
;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 291 views
  • 2 likes
  • 4 in conversation