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

## Using in= while setting 2 datasets

I have used the following code:

``````data people;
input obs name\$;
cards;
1 Frank
2 Joan
3 Sui
4 Jose
5 Burt
6 Kelly
7 Juan
;
run;
data money;
input name\$ sal;
cards;
Frank 100
Joan 210
Sui 250
Jose 330
;
run;

data work.empsalary;
set work.people (in = inemp) work.money (in = insal);
if insal and inemp;
run;``````

How can the observations be 0 when there are common variables in both sets. can anyone explain it to me.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Lapis Lazuli | Level 10

## Re: Using in= while setting 2 datasets

``````data people;
input obs name\$;
cards;
1 Frank
2 Joan
3 Sui
4 Jose
5 Burt
6 Kelly
7 Juan
;
run;
proc sort data = &syslast;by name;

PROC sql; describe table &syslast;quit;
data money;
input name\$ sal;
cards;
Frank 100
Joan 210
Sui 250
Jose 330
;
run;
proc sort data = &syslast;by name;

PROC sql; describe table &syslast;quit;

data work.empsalary;
merge work.people (in = inemp) work.money (in = insal);
by name;
if insal and inemp then output;
run;
PROC sql; describe table &syslast;quit;
proc print;
run;``````

the set statement stacks the output

use merge+by instead, which requires data attribute says it is sorted,

even though the data in alpha order by name.

hth

Ron Fehd  data structure mostly, sometimes algorithm maven

2 REPLIES 2
Diamond | Level 26

## Re: Using in= while setting 2 datasets

You are setting the data work.people first then afterwards money, therefore the logic if insal and inemp can never be true as both rows never appear on the same row.  Perhaps you meant to merge the two datasets:

``````data work.empsalary;
merge work.people (in=inemp) work.money (in=insal);  by name;
if insal and inemp;
run;``````

Note, both have to be sorted by name first.

Lapis Lazuli | Level 10

## Re: Using in= while setting 2 datasets

``````data people;
input obs name\$;
cards;
1 Frank
2 Joan
3 Sui
4 Jose
5 Burt
6 Kelly
7 Juan
;
run;
proc sort data = &syslast;by name;

PROC sql; describe table &syslast;quit;
data money;
input name\$ sal;
cards;
Frank 100
Joan 210
Sui 250
Jose 330
;
run;
proc sort data = &syslast;by name;

PROC sql; describe table &syslast;quit;

data work.empsalary;
merge work.people (in = inemp) work.money (in = insal);
by name;
if insal and inemp then output;
run;
PROC sql; describe table &syslast;quit;
proc print;
run;``````

the set statement stacks the output

use merge+by instead, which requires data attribute says it is sorted,

even though the data in alpha order by name.

hth

Ron Fehd  data structure mostly, sometimes algorithm maven

Discussion stats
• 2 replies
• 973 views
• 0 likes
• 3 in conversation