DATA Step, Macro, Functions and more

Combining SAS logical operators

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

Combining SAS logical operators

Hi Everyone

When I run the below data step and see the result, I am not getting any records where there is a 'y' flag and there definitely should be (no errors either). When I run some of these operators individually, I do get 'y' flags. Is there some syntax issue with combining operators?

Paul

data s0All (keep=cnty_name County place Year start stop exit filing_cat1 agecat4 Jur2012 Jur2011 Jur2010);

set workep;

if (exit="ZTC" and start < 01/02/2012) or (stop < 01/02/2012) then Jur2012="y";

else Jur2012="n";

if (exit="ZTC" and start < 01/02/2011) or (stop < 01/02/2011 and start < 01/02/2011) then Jur2011="y";

else Jur2011="n";

if (exit="ZTC" and start < 01/02/2010) or (stop < 01/02/2010 and start < 01/02/2010) then Jur2010="y";

else Jur2010="n";

run;


Accepted Solutions
Solution
‎01-29-2013 11:55 AM
Super User
Posts: 19,791

Re: Combining SAS logical operators

Is your start variable a character or a number? Is it formatted as a date?

I think your date part is wrong anyways, should be start<'01Jan2010'd type notation rather than what you have.

You may also want to verify the case of your 'y' to make sure none are 'Y' or "N".

View solution in original post


All Replies
Solution
‎01-29-2013 11:55 AM
Super User
Posts: 19,791

Re: Combining SAS logical operators

Is your start variable a character or a number? Is it formatted as a date?

I think your date part is wrong anyways, should be start<'01Jan2010'd type notation rather than what you have.

You may also want to verify the case of your 'y' to make sure none are 'Y' or "N".

Regular Contributor
Posts: 216

Re: Combining SAS logical operators

Hi Reeza, It is a number (01/01/2003), formatted as a date field. However, your suggestion above resolved it. I don't totally understand because it was evaluating it prior. Regardless, thank you.

Paul

Super User
Posts: 5,504

Re: Combining SAS logical operators

Paul,

The difference is this.  How would you feel about making this comparison:

if start < 0.5 / 2012 then do;

That's actually the comparison you were making.  01/02/2012 says divide 1 by 2, then divide the result by 2012.  Reeza showed you the right way to refer to a particular day on the SAS date scale.

Good luck.

Regular Contributor
Posts: 216

Re: Combining SAS logical operators

Posted in reply to Astounding

Thanks Astounding. I see.

Paul

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 195 views
  • 0 likes
  • 3 in conversation