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

Hi!

 I have tried to create a dummy-variable where "1" indicates that the event (case_start) has occured, and "0" the opposite. "1" should indicate that the event (Case_start) occured after 01.01.2018, and "0" should indicate that the event (case_start) has occured before 01.01.2018. 

 

data tuetravelexpenses_cases;
set tuetravelexpenses_cases;
if '04OCT2016:23:00:00'<case_start<'31DES2017:23:00:00' then observation_period='0';
run;

 

My problem is that every event gets "0", instead of only the events before 01.01.2018. I have also tried

 

if case_start>31DES2017:23:00:00" then observation_period="0", but i get the same result.

 

Can someone help?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Assuming the values of CASE_START are true SAS date-time values (and not character strings or SAS date values)

 

if '04OCT2016:23:00:00'dt<case_start<'31DES2017:23:00:00'dt then observation_period='0';

 

Also, not sure why you want the zero in quotes as a character variable, you could just use 0 with no quotes.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Assuming the values of CASE_START are true SAS date-time values (and not character strings or SAS date values)

 

if '04OCT2016:23:00:00'dt<case_start<'31DES2017:23:00:00'dt then observation_period='0';

 

Also, not sure why you want the zero in quotes as a character variable, you could just use 0 with no quotes.

--
Paige Miller
amsa1996
Fluorite | Level 6
Thank you for your help! It worked!
Kurt_Bremser
Super User

Maxim 2: Read the Log. If that is not sufficient to give you a clue, post it here, so we can explain what happens. Use </> to post the log.

 

Here:

if '04OCT2016:23:00:00'<case_start<'31DES2017:23:00:00' 

you use character values that are not SAS datetime literals (constants). Datetime literals must be written with correct month names (DEC for December, for instance) and the closing quote must be followed immediately by the letters dt.

amsa1996
Fluorite | Level 6

Correct! It worked

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!

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