BookmarkSubscribeRSS Feed
MichelleKorson
Calcite | Level 5

 I have a data about the Ufo and now I want to study whether the time will influence the sightings,  I want to divide time in four parts and assumed that the Morning time is as 5:00-7:00, Daytime 7:00-17:00, Evening time 17:00-19:00 and night time is  19:00-5:00. How can I write a code about that? Should I use the if else statement?

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Tons of ways to do conditional processing. I would use the Select Statement in this case.

ballardw
Super User

It appears that your values are actually date times. Maybe. CSV, which the file isn't, is not a SAS data set.

Extract the Time value into a time variable. If the date time is a SAS date time value then the function TIMEPART will do that.

Then use a custom format similar to the following with that TIME only variable.

proc format;
value mytime
'19:00't < - '23:59't = 'Night'
'00:00't -   '05:00't = 'Night'
'05:00't < - '07:00't = 'Morning'
'07:00't < - '17:00't = 'Daytime'
'17:00't < - '19:00't = 'Evening'
;
run;

 

I suggest a format as you do not need to add additional variables but create a new format and use that if you decide you want 04:00 to 08:00 to be morning later, or perhaps reduce to 3 categories, or add. SAS will use

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
  • 400 views
  • 0 likes
  • 4 in conversation