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

data test1;
input id $ marks1 ;
datalines;
a1 10
a2 20
a3 30
a4 40
a7 70
a8 80
a9 90
a10 100
;
data test2;
input id $ marks2;
datalines;
a1 10
a2 20
a3 30
a4 40
a5 50
a6 60
a7 70
a8 80
a9 90
a10 100
;

proc sort data=test1;
by id;
proc sort data=test2;
by id;

data merge1;
merge test1 test2;
by id;

 

the current result is the following 

1a11010 
2a10100100 
3a22020 
4a33030 
5a44040 
6a5.50 
7a6.60 
8a77070 
9a88080 
10a99090

 

But I just want to show the output contain in test two but missing in test one by id

the following is the result I desire:

a5 50

a6 60

 

please help! I can't find similar examples in my lecture notes ,wanna cry

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Do you want the observations that are not in TEST1?

data merge1;
  merge test1(in=in1) test2(in=in2);
  by id;
  if not in1;
run;

Or the observations that have a missing value for the variable MARKS1?

data merge1;
  merge test1(in=in1) test2(in=in2);
  by id;
  if missing(marks1);
run;

View solution in original post

4 REPLIES 4
chriswong1386
Calcite | Level 5
need to be done by a data set ,can not use proc sql
mkeintz
PROC Star

Look at

  1. The  IN= Data Set Option  
    and
  2. The  Subsetting IF statement.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

Do you want the observations that are not in TEST1?

data merge1;
  merge test1(in=in1) test2(in=in2);
  by id;
  if not in1;
run;

Or the observations that have a missing value for the variable MARKS1?

data merge1;
  merge test1(in=in1) test2(in=in2);
  by id;
  if missing(marks1);
run;
AndreaVianello
Obsidian | Level 7

data test1;
input id $ marks1 ;
datalines;
a1 10
a2 20
a3 30
a4 40
a7 70
a8 80
a9 90
a10 100
;
data test2;
input id $ marks2;
datalines;
a1 10
a2 20
a3 30
a4 40
a5 50
a6 60
a7 70
a8 80
a9 90
a10 100
;
run;

 

proc sql;
create table want as
select test1.id, marks1, marks2
from test1 right join test2
on test1.id=test2.id
; quit;

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 543 views
  • 3 likes
  • 4 in conversation