I have a variable with dates and time values such as:
22SEP15:15:10:35
06JUN16:15:03:53
I would like to create three new variables based on if the value start with 01-10,11-20 or 21-31.
But I am having problems only picking up the information of the first two digits.
Sounds like you want to get to the day of the month.
day(datepart(datetime_var))
And generate a new variable with 3 values.
day=day(datepart(datetime_var));
if 0<day<=10 then month_part=1;
else if day <=20 then month_part=2;
else if day <=31 then month_part=3;
else month_part=.;
Do you have a numeric variable formatted as datetime (aka proper sas datetime) or a string containing a datetime-value? When working with date and time data it is almost always useful to convert the data to a sas datetime.
And unfortunately i can't see any connection between the datetimes and the new variables.
It seems like I have SAS datetime.
For the regression I am running I would like to see if it matters if it's the beginning, middle or the end of a month.
So I would like all events that happened during the 01-10 date of the months in one category, the events that happened during day 11-20 of the months in another and the last 21-31 in a third category.
But I am stuck, I just want SAS to check the first two numbers and sort after that, but can't get it to work.
Thanks for all help
Sounds like you want to get to the day of the month.
day(datepart(datetime_var))
And generate a new variable with 3 values.
day=day(datepart(datetime_var));
if 0<day<=10 then month_part=1;
else if day <=20 then month_part=2;
else if day <=31 then month_part=3;
else month_part=.;
Hi and welcome to the SAS Community 🙂
Are these actual datetime values (numeric) or character values?
I'm not sure to be honest, I just imported a dataset and did proc print to have a look at it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.