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

Hi, I need assistance with creating  categorical time group (intervals) variables to be used in logistic regression.

Similar to the way you would create an AGEGROUP variable. I'm currently using SAS Studio.

 

Here is my code so far:

 

Data BK4;
set BK3;
FORMAT Timeconsumed time6.;
if Timeconsumed  ge 10:30 and ln 11:30 then LunchPeriod1= 1;
else LunchPeriod1= 0;
if Timeconsumed  ge 11:30 and ln 12:30 then LunchPeriod2= 1;
else  LunchPeriod2= 0;
if Timeconsumed  ge 12:30 and ln 13:30 then LunchPeriod3= 1;
else  LunchPeriod3= 0;
if Timeconsumed  ge 13:30 and ln 14:30 then LunchPeriod4= 1;
else  LunchPeriod4= 0;
if Timeconsumed  ge 14:30 then LunchPeriod5= 1;
else LunchPeriod5= 0;
else= .;
run;

 

I keep getting these error messages:

 

ERROR 22-322: Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, LE, LT, NE, NG, NL, ^=, ~=. 

 
ERROR 76-322: Syntax error, statement will be ignored.
 
Any help would be much appreciated!
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Are you looking to do this?

if '10:30't<=Timeconsumed<'11:30't then LunchPeriod1= 1;
else LunchPeriod1= 0;

If yes, you could use that syntax for all the others

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Are you looking to do this?

if '10:30't<=Timeconsumed<'11:30't then LunchPeriod1= 1;
else LunchPeriod1= 0;

If yes, you could use that syntax for all the others

Haris
Lapis Lazuli | Level 10

First, not completely sure on this but I don't think SAS reads 10:30 literally as time.  Most likely you need to to use something like '10:30't formulation.  You can look up how to reference time yourself.

 

Second, your AND is followed by LN which is a natural log.  I believe you need to use LE for 'less than or equal to'.  You also need to repeat the variable name after the AND like this:

 

data BK4;
  set BK3;
  if TimeConsumed GE '10:30't AND TimeConsumed LE '11:30't
    then LunchPeriod1= 1;
    else LunchPeriod1= 0;
run;

The code is not tested.  You'll need to look up how to reference a variable with time format.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 847 views
  • 0 likes
  • 3 in conversation