Datastep --- Comparision

  • Follow


Dear all:

This is the dataset i have and

data have;
  input name $ deg $ dep $ res test $ temp bp1 bp2 ds $ ;
  cards;
   BHA SSP DMA 12 BUN 89 12 12 AE
   BHA SSP DMA 11 BUN 11 19	11 AE
   BAR DCO CLI 18 BUN 11 19 98 AE
   MEL DMS DMA 11 BUN 98 10	17 AE
   BHA SSP ADN 12 BUN 89 12 12 SN
   BHA SSP ACN 12 BUN 89 12 12 SN
   BHA SSP ANM 12 BUN 89 12 12 SN
   BHA SSP ANM 12 BUN 89 12 12 SN
   BAR DCO CLI 18 BUN 11 19 98 SN
   MEL DMS DMA 11 BUN 98 10	17 SN

   ;
run;

Variable DS represents the name of the dataset they came from (AE or
SN)..
I need to compare datapoints that came from DS = 'AE' to DS = 'SN' and
create a dataset
if there were any changes to the
variable(name,deg,dep,res,test,temp,bp1,bp2) values from data set AE
to dataset SN,or any additions or any deletions

i have tried proc compare  and proc sort with nodupkey  but was not
able to get desired results


Thanks in Advance
Al;
0
Reply Al 6/18/2010 8:45:25 PM

Hi Al

What's missing is a key which clearly identifies a record within AE or
SN - at least I can't figure out which variable combination could be
used to build such a composite key.

If no such key exists it's not possible to determine if a record from
AE and SN represent the same event even if some of the data are
different.

Best you can do is to determine whether you have matching records from
AE and SN (using a natural key) or not. That's what the code below
does.

In case you have a key in your real data then you could of course
split the data set into two data sets (haveAE haveSN as done below)
and then use a proc compare. The key variables would be used in the BY
statement, the rest in VAR and WITH.


data have;
  input name $ deg $ dep $ res test $ temp bp1 bp2 ds $ ;
  cards;
BHA SSP DMA 12 BUN 89 12 12 AE
BHA SSP DMA 11 BUN 11 19 11 AE
BAR DCO CLI 18 BUN 11 19 98 AE
MEL DMS DMA 11 BUN 98 10 17 AE
BHA SSP ADN 12 BUN 89 12 12 SN
BHA SSP ACN 12 BUN 89 12 12 SN
BHA SSP ANM 12 BUN 89 12 12 SN
BHA SSP ANM 12 BUN 89 12 12 SN
BAR DCO CLI 18 BUN 11 19 98 SN
MEL DMS DMA 11 BUN 98 10 17 SN
;
run;

proc sort data=have;
  by name deg dep res test temp bp1 bp2;
run;

data haveAE haveSN;
  set have;
  if ds='AE' then output haveAE;
  else if ds='SN' then output haveSN;
  drop ds;
run;

data BothAEandSN onlyAE onlySN;
  merge haveAE (in=inAE) haveSN (in=inSN);
  by name deg dep res test temp bp1 bp2;
  if inAE and inSN then output BothAEandSN;
  else if inAE and NOT inSN then output onlyAE;
  else if NOT inAE and inSN then output onlySN;
run;


HTH
Patrick
0
Reply Patrick 6/19/2010 1:08:37 AM


1 Replies
168 Views

(page loaded in 0.035 seconds)

Similiar Articles:













7/15/2012 5:05:55 PM


Reply: