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

Hi everyone,

 

I have a variable V3 that is conditional on other variables V1 and V2. I need to assign missing values (-99) for V3 in cases where this condition is not satisfied: If V1=1 and V2=3

 

Can I write this code:if NOT( V1=1 and V2=3) then V3=-99?

 

I am not sure how to cover all cases in which this combination of conditions is satisfied.

 

Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

> Can I write this code:if NOT(V1=1 and V2=3) then V3=-99?

Yes you can write this code.

Even better than asking would be trying. That would faster as well!

View solution in original post

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

> Can I write this code:if NOT(V1=1 and V2=3) then V3=-99?

Yes you can write this code.

Even better than asking would be trying. That would faster as well!

Orchidn
Fluorite | Level 6

Hi Chris,

thanks, I will try that when I get access to my SAS software / I only have access to email right now - on my way home:).

Best regards!

ballardw
Super User

@Orchidn wrote:

Hi everyone,

 

I have a variable V3 that is conditional on other variables V1 and V2. I need to assign missing values (-99) for V3 in cases where this condition is not satisfied: If V1=1 and V2=3

 

Can I write this code:if NOT( V1=1 and V2=3) then V3=-99?

 

I am not sure how to cover all cases in which this combination of conditions is satisfied.

 

Thank you very much!


 

Why not assign a SAS MISSING value instead of -99? Any use of V3 is likely going to have to work around that numeric value. Such as if you want the mean value of V3 do you want to include -99 in the calculations.

You can assign special missing values to variable such as .A to differentiate between different types of missing if that might be important, such as assigned because of this condition and missing from data entry or other cause.

data example;
   input v1 v2 v3;
   if NOT( V1=1 and V2=3) then V3=.A;
datalines;
1 3 6
2 1 5
1 3 8
;
run;

proc print data=example;
run;

You can create custom formats that would display the value .A as something like "Rule 1" or "Improbable" or whatever might make sense. And any numeric calculations involving V3 will not attempt to use -99 (or other code).

Proc means data=example;
run;

will show 2 values for V3, mean 7, std dev about 1.41, min=6 and max=8.

Tom
Super User Tom
Super User

Note that NOT is not a function. It is an operator.  In particular a unary operator.  The parenthesis in your expression are for grouping, not marking a function call.

Orchidn
Fluorite | Level 6

Thank you so much!

Orchidn
Fluorite | Level 6
Thank you so much!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 11433 views
  • 7 likes
  • 4 in conversation