SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jffeudo86
Quartz | Level 8

Hi,

 

Just wanted to confirm: if a and ^b in "IF a AND ^b THEN OUTPUT ..." can be read as "if in a and not in b", is that correct?  

 

I have googled this particular syntax and it doesn't appear in the results.

 

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@jffeudo86 wrote:

Hi,

 

Just wanted to confirm: if a and ^b in "IF a AND ^b THEN OUTPUT ..." can be read as "if in a and not in b", is that correct?  

 

I have googled this particular syntax and it doesn't appear in the results.

 

Thanks.

 


Depends. How did the variables A and B get assigned. By "in" do you mean coming from a data set? Then this would be true only if the dataset option in= was used:

 

data junk;
   merge 
   one (in=a)
   two (in=b)
   ;
   if a and not b then output;
end;

But "in a" above would mean "in data set one". There is no automatic membership logical variable set based on the source data set.

 

If the question is about the logical structure then there are different ways of doing the "not":

data example;
   input a b;
   z= a and ^b;
   y= a and not b;
   x= a and ~ b;
datalines;
1 1
1 0
0 0
0 1
;
run;

The logical value is the same but not all keyboards use the ~ or ^.

 

And note that if you only have one data set on the DATA statement so that all of the output is going to that set conditionally then you don't even need the OUTPUT as

 

if a and not b; 

 

is a subsetting if and the records that match the logic are the only ones kept.

View solution in original post

2 REPLIES 2
ballardw
Super User

@jffeudo86 wrote:

Hi,

 

Just wanted to confirm: if a and ^b in "IF a AND ^b THEN OUTPUT ..." can be read as "if in a and not in b", is that correct?  

 

I have googled this particular syntax and it doesn't appear in the results.

 

Thanks.

 


Depends. How did the variables A and B get assigned. By "in" do you mean coming from a data set? Then this would be true only if the dataset option in= was used:

 

data junk;
   merge 
   one (in=a)
   two (in=b)
   ;
   if a and not b then output;
end;

But "in a" above would mean "in data set one". There is no automatic membership logical variable set based on the source data set.

 

If the question is about the logical structure then there are different ways of doing the "not":

data example;
   input a b;
   z= a and ^b;
   y= a and not b;
   x= a and ~ b;
datalines;
1 1
1 0
0 0
0 1
;
run;

The logical value is the same but not all keyboards use the ~ or ^.

 

And note that if you only have one data set on the DATA statement so that all of the output is going to that set conditionally then you don't even need the OUTPUT as

 

if a and not b; 

 

is a subsetting if and the records that match the logic are the only ones kept.

jffeudo86
Quartz | Level 8
Thank you! I wanted to know if the caret symbol (^) is read as "not".

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 17505 views
  • 0 likes
  • 2 in conversation