BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NKormanik
Barite | Level 11

Given A, B, C

In order for A to stay, it needs to be greater than either B or C.

If A is less than BOTH B and C, it gets tossed.

 

In SAS-speak, the following doesn't appear to be correct.  Can someone please offer guidance?

 

if A < (B and C) then A = . ;

 

Using 'or' doesn't seem to work either.

 

Oh, and, these are numeric variables, numbers....

 

Hey, it's been a long day.

 

 

1 ACCEPTED SOLUTION
5 REPLIES 5
KaueMAlmeida
Obsidian | Level 7

I haven't tried this code, but it something like that...

If A < B or A < C then A = .;
If A gt B or A gt C then A = .;

 

Those variables are numerical? What kind of values do you have on each column? May you will have some problem when calculating the values.

andreas_lds
Jade | Level 19

In order for A to stay, it needs to be greater than either B or C.

Must be translated to the logic expression A > B or A > C.

 

If A is less than BOTH B and C

Means: A < B and A < C

 

Next step: what should happen if A = B and A = C?

And: why should A be set to missing if it should "stay"?

NKormanik
Barite | Level 11

Terrific, @Kurt_Bremser .  How easy that was.  Thanks!

 

Shows the great usefulness of max(), min().  And also, not().

 

ballardw
Super User

@NKormanik wrote:

Given A, B, C

In order for A to stay, it needs to be greater than either B or C.

If A is less than BOTH B and C, it gets tossed.

 

In SAS-speak, the following doesn't appear to be correct.  Can someone please offer guidance?

 

if A < (B and C) then A = . ;

 

Using 'or' doesn't seem to work either.

 

Oh, and, these are numeric variables, numbers....

 

Hey, it's been a long day.

 

 


It is "correct" in the way that SAS works. When you place a comparison in () such as (B and C) it evaluates that expression. Then returns the result of that expression as 1 (for true) or 0 for false. The comparison (B and C), since you use a Logic expression is testing "is B true and is C true". Which returns 1 when both are "true" or 0 if any are not "true". Values of 0 or missing are not "true".

Example:

data example;
   input b c;
   result = (b and c);
datalines;
1 1
0 1
. 1
. .
2 3
-4 5
6 7
1000000 .000004
;

So your code was asking, essentially, is "A <0" or is "A<1" depending on the values of B and C.

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 432 views
  • 4 likes
  • 5 in conversation