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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 16947 views
  • 0 likes
  • 2 in conversation