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

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


1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

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

5 REPLIES 5
Scott_Mitchell
Quartz | Level 8

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

DR_Majeti
Quartz | Level 8

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.

JerryLeBreton
Pyrite | Level 9

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.

DR_Majeti
Quartz | Level 8

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

Mirisage
Obsidian | Level 7

Hi Scott_Mitchell, DR.Majeti and JerryLeBreton,

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

Regards

Mirisage

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 6648 views
  • 12 likes
  • 4 in conversation