DATA Step, Macro, Functions and more

FINDING THE MISSING observation

Reply
N/A
Posts: 0

FINDING THE MISSING observation

I can't find the missing school: Los_angeles has 2140 observations and KALA has 2141 observations. I tried using the following code to determine which observation is missing but can't.

DATA MATCH LOS_ANGELES KALA;
MERGE LOS_ANGELES (IN=L)
KALA (IN=K);
BY SCHNAME;
IF L AND NOT K THEN OUTPUT LOS_ANGELES;
IF NOT L AND K THEN OUTPUT KALA;
IF L AND K THEN OUTPUT MATCH;
RUN;
Super Contributor
Posts: 273

Re: FINDING THE MISSING observation

Teresa,

you have made one mistake and think about the second remark
Andre

1) you are overwriting your source LOS_Angeles With your code replacing it!

see how to avoid this

[PRE]
25 DATA MATCH LOS K;
26 MERGE LOS_ANGELES (IN=L)
27 KALA (IN=K);
28 BY SCHNAME;
29 IF L AND NOT K THEN OUTPUT LOS;
30 IF NOT L AND K THEN OUTPUT K;
31 IF L AND K THEN OUTPUT MATCH;
32 RUN;

INFO: The variable one on data set WORK.LOS_ANGELES will be overwritten by data set WORK.KALA.
INFO: The variable two on data set WORK.LOS_ANGELES will be overwritten by data set WORK.KALA.
NOTE: There were 2 observations read from the data set WORK.LOS_ANGELES.
NOTE: There were 3 observations read from the data set WORK.KALA.
NOTE: The data set WORK.MATCH has 2 observations and 4 variables.
NOTE: The data set WORK.LOS has 0 observations and 4 variables.
NOTE: The data set WORK.K has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.01 seconds
[/PRE]


and second point
How are you sure there is only one record that differ?

This can also happen with this startpoint

[PRE]
Data los_angeles;
input schname $1. one two;
datalines;
A 12 36
B 15 25
;
data Kala;
input schname $1. one two three;
datalines;
D . 36 45
E 75 27 .
C 1 2 3
;
run;
Proc sort data=Kala; by schname;run;

INFO: The variable one on data set WORK.LOS_ANGELES will be overwritten by data set WORK.KALA.
INFO: The variable two on data set WORK.LOS_ANGELES will be overwritten by data set WORK.KALA.
NOTE: There were 2 observations read from the data set WORK.LOS_ANGELES.
NOTE: There were 3 observations read from the data set WORK.KALA.
NOTE: The data set WORK.MATCH has 0 observations and 4 variables.
NOTE: The data set WORK.LOS has 2 observations and 4 variables.
NOTE: The data set WORK.K has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
[/PRE]
N/A
Posts: 0

Re: FINDING THE MISSING observation

Thanks Andre! I appreciate your help.
Ask a Question
Discussion stats
  • 2 replies
  • 119 views
  • 0 likes
  • 2 in conversation