Help using Base SAS procedures

Merging Question_difference between if a and if a=1?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

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;

data ADVERSE;

input SUBJECT EVENT $;

cards;

124263 HEADACHE

124266 FEVER

124266 NAUSEA

124267 FRACTURE

;

run;

/*sorting*/

proc sort data= PATDATA;

  by subject;

run;

proc sort data= ADVERSE;

  by subject;

run;

/*merging by giving IF a statement*/

DATA alldata0;

     MERGE adverse (in=a)

                patdata (in=b);

BY subject;

IF a;

RUN;

proc print; run;

Below is the resultant table.

1124263HEADACHEA
2124266FEVERB
3124266NAUSEAB
4124267FRACTURE

/*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: 297

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

View solution in original post


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

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: 64

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: 85

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

Posted in reply to DR_Majeti

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: 64

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

Posted in reply to JerryLeBreton

, 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?

Posted in reply to DR_Majeti

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 265 views
  • 12 likes
  • 4 in conversation