## Merging Question_difference between if a and if a=1?

Solved
Super Contributor
Posts: 338

# Merging Question_difference between if a and if a=1?

Hi SAS Forum,

I am reviewing a sas code written by someone else who has used "if a =1" statement which I am not familier with.

I am familier only with "if a" statement.

To test, whether  both "if a =1" and "if a" statements are producing the exactly same resutls, I just did the following experiment.

Suppose I have below two data sets.

data PATDATA;

input SUBJECT TRT_CODE \$;

cards;

124263 A

124264 A

124265 B

124266 B

;

run;

input SUBJECT EVENT \$;

cards;

124266 FEVER

124266 NAUSEA

124267 FRACTURE

;

run;

/*sorting*/

proc sort data= PATDATA;

by subject;

run;

by subject;

run;

/*merging by giving IF a statement*/

DATA alldata0;

patdata (in=b);

BY subject;

IF a;

RUN;

proc print; run;

Below is the resultant table.

 1 124263 HEADACHE A 2 124266 FEVER B 3 124266 NAUSEA B 4 124267 FRACTURE

/*merging by giving IF a=1 statement*/

This also gave me the same above output table.

So, I concluded that both IF a=1 and IF a statements give us the identical resutls.

Question:

Could any merging expert confirm whether I could generalize my conclusion for any situation.

Thanks

Mirisage

Accepted Solutions
Solution
‎07-28-2013 09:46 PM
Super Contributor
Posts: 312

## Re: Merging Question_difference between if a and if a=1?

Hi Mirisage,

You are correct in saying that if A is the same if A = 1.

The In dataset option creates a boolean variable that indicates the dataset from which the data came.

You can only see the values contained in A by creating another variable.

The following is a simple example of what A actually contains.

DATA STAFF;

SET SASHELP.CLASS (IN=A) SASHELP.CLASS;

INA = A;

RUN;

I hope this helps.

Regards,

Scott

All Replies
Solution
‎07-28-2013 09:46 PM
Super Contributor
Posts: 312

## Re: Merging Question_difference between if a and if a=1?

Hi Mirisage,

You are correct in saying that if A is the same if A = 1.

The In dataset option creates a boolean variable that indicates the dataset from which the data came.

You can only see the values contained in A by creating another variable.

The following is a simple example of what A actually contains.

DATA STAFF;

SET SASHELP.CLASS (IN=A) SASHELP.CLASS;

INA = A;

RUN;

I hope this helps.

Regards,

Scott

Contributor
Posts: 72

## Re: Merging Question_difference between if a and if a=1?

Mirisage,

Both statements If a=1 and If a have identical results, Because generally SAS considers the truth value to get executed where 1=true and 0=false. In merging 1=contribution of that particular dataset and 0=not. This (In=) also helps in grouping of observations.

Frequent Contributor
Posts: 88

## Re: Merging Question_difference between if a and if a=1?

Its also worth noting that SAS considers any value as 'true' if the result of the expression is anything other than 0 or missing.

So 99 and -123 would both considered as 'true'.  Can often be useful.

Contributor
Posts: 72

## Re: Merging Question_difference between if a and if a=1?

, Thank you for the information. I got a new point..

Super Contributor
Posts: 338

## Re: Merging Question_difference between if a and if a=1?

Hi Scott_Mitchell, DR.Majeti and JerryLeBreton,

Many thanks to each one of you for this great help.

Regards

Mirisage

🔒 This topic is solved and locked.