BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sundeep_M
Calcite | Level 5

How to separate date and time when combined and assign time with am and pm.

And also can you please write down the code.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
/*** UNTESTED CODE ***/

data want;
     infile "filename.txt";
     input name $10. & datetime :ANYDTDTM16.;
     date=datetpart(datetime);
     time=timepart(datetime);
     format date ddyymm8. time timeampm8.;
run;
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Give us an example of your input data. Please specify in your reply whether or not the data is already in a SAS data set as numeric or character, and whether it is formatted. If the data is not in a SAS data set and has to be read in from some text file, please show us an example of such a date and time.


Also, please, we are trying to help you, and you can help us by providing a more specific subject line to your original question. The existing subject line "SAS query" could apply to any question about anything in SAS.

--
Paige Miller
Sundeep_M
Calcite | Level 5

SIR HERE IS THE DATA SET

Mr. Manoj     18/02/2007:3:30

Mr. Jacob     19/02/2007:4:15

Mr.Anil          19/02/2007:13:00

Mr.Rathod     20/03/2007:14:30

 

Sir for the above data set can you explain how to separate data and time and assign time am/pm.

Thanks for your feedback i will change my subject.

PaigeMiller
Diamond | Level 26

@Sundeep_M wrote:

SIR HERE IS THE DATA SET

Mr. Manoj     18/02/2007:3:30

Mr. Jacob     19/02/2007:4:15

Mr.Anil          19/02/2007:13:00

Mr.Rathod     20/03/2007:14:30

 

Sir for the above data set can you explain how to separate data and time and assign time am/pm.

Thanks for your feedback i will change my subject.


Thank you, but is this a SAS data set, or text that has to be read in from some external file?

 

Also, we request that you change the subject line of the original post in this thread.

--
Paige Miller
Sundeep_M
Calcite | Level 5

Sir this is a text that has to be read from external file

PaigeMiller
Diamond | Level 26
/*** UNTESTED CODE ***/

data want;
     infile "filename.txt";
     input name $10. & datetime :ANYDTDTM16.;
     date=datetpart(datetime);
     time=timepart(datetime);
     format date ddyymm8. time timeampm8.;
run;
--
Paige Miller
Kurt_Bremser
Super User

See my footnotes for hints on posting data in form of code.

 

Note that this is a website for helping people do their work, not doing their work for them. If you need someone to write your code, hire a consultant.

Work through the free Programming 1 course to have all the basics settled.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1003 views
  • 0 likes
  • 3 in conversation