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

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
Ron_MacroMaven
Lapis Lazuli | Level 10
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

 

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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. 

Ron_MacroMaven
Lapis Lazuli | Level 10
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

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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