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.
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
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
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
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.
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.
Hi Scott_Mitchell, DR.Majeti and JerryLeBreton,
Many thanks to each one of you for this great help.
Regards
Mirisage
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.