Hi ! Please I need you help+++
I have a time variable HH:MM called "timestop" and I would like to create a new categorical variable "timestopnight" stating 1 if the timestop was between 23:00 and 7:00 and 0 if the timestop was between 07:00 and 23:00.
I have tried several codes like the following but none worked.
data dataset ; set dataset;
if timestop < '07:00't then timestopnight=1;
if timestop > '23:00't then timestopnight=1;
if '07:00't =<timestop =< '23:00't then timestopnight=0;
run;
Thanks a lot for your help 🙏
Rodrigue
Please post the complete log from that step.
If timestop is a SAS time, this will work:
timestopnight = ifn('07:00't le timestop le '23:00't,0,1);
Be observant if timestop is a datetime instead of just time.
I think you need to use if else if.
Can also do a boolean.
timestopnight=07:00't le timestop le 23:00't;
This will assign 1 if the condition is true and 0 if it's false.
Please post the complete log from that step.
If timestop is a SAS time, this will work:
timestopnight = ifn('07:00't le timestop le '23:00't,0,1);
Be observant if timestop is a datetime instead of just time.
Thank you very much Kurt. It seems to work perfectly well for subjects who have a time in the timestop variable.
The only problem is that I have a 1 in the timestopnight column in patients who don't have value for the timestop variable.
I've tried to insert before but it didn't work.
timestopnight = .;Could you help me with that ?
I have attached the log but the variable names are different since I've tried to simplify for the post.
Thanks again for your help+++
Rodrigue
I found the solution adding
if not missing (timestop)
MISSING values are always less than any actual value.
Always.
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.