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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.