Hello all;
I have two datasets, one and two. dataset two is subset of dataset one with less observations. I want to add a numerical binary variable (z) to dataset one, that the value of z=1 for observations that are in dataset two and z=0 for those observations that are not in dataset two. Appreciate for any help.
data one;
input x1 ;
datalines;
...
;
run;
data two;
input x1;
datalines;
...
run;
data one;
input x1$;
datalines;
a
b
c
d
;
run;
data two;
input x1$;
datalines;
a
b
run;
proc sql;
create table three as
select one.x1,two.x1 as x2,
case
when one.x1 = two.x1 /*STRIP if needed*/
then 1 else 0 end as z
from one full join two
on one.x1 = two.x1;
quit;
Does the above help, SQL is efficient as there is no previous sort required, but will need creating a third dataset.
data one;
input x1$;
datalines;
a
b
c
d
;
run;
data two;
input x1$;
datalines;
a
b
run;
proc sql;
create table three as
select one.x1,two.x1 as x2,
case
when one.x1 = two.x1 /*STRIP if needed*/
then 1 else 0 end as z
from one full join two
on one.x1 = two.x1;
quit;
Does the above help, SQL is efficient as there is no previous sort required, but will need creating a third dataset.
Is this based on a single value in the data set or does the whole line need to match?
You need to provide more details but otherwise, just do a MERGE and look at the IN option.
data want;
merge one (in=a) two (in=b);
by <you need to fill in>; *you have not specified the problem well enough to indicate what goes here;
if a & b then z=0;
else if b then z=1;
run;
See Example 5 in the documentation for more details.
https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lestmtsref&docsetTarget=n...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.