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.
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
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.