An Idea Exchange for SAS software and services

Comments
by Respected Advisor
on ‎07-08-2013 05:11 PM

The KEY parameter is used to override the default key variable for the find.  Therefore there is no error to report or warn you about.

Best practice is omit the KEY parameter when you don't need it as in your example.

by Occasional Contributor smiller933
on ‎07-10-2013 01:46 PM

You make a good point in that in the first example, the key parameter isn't necessary. I came up with an example that I think better illustrates the point. In this case, owner2 is misspelled as ownr2.

Even a note indicating that ownr2 is an uninitialized variable would be helpful -- I'd consider that to be a reasonable alternative to my original suggestion.

data vehicles_with_delq_tickets;

   infile datalines dsd;

   format date date9. VIN $15.;

   informat date date9.;

   input owner1 owner2 date VIN;

datalines;

1111,,11jan2013,XJJ7

2222,4444,15jan2013,RTUS

;

run;

data people;

   infile datalines dsd;

   input id name $15.;

datalines;

1111,First Last1

1777,First Last2

2222,First Last3

2777,First Last4

3111,First Last5

4444,First Last6

;

run;

data people_with_delq_tickets;

   keep name date VIN;

   *  Create hash object *;

   if _N_ = 1 then do;

      if 0 then set people;

      declare hash ppl (dataset: 'people');

      ppl.definekey ('id');

      ppl.definedata ('name');

      ppl.definedone ();

   end;

   set vehicles_with_delq_tickets;

   *  Output one record for each owner *;

   if (0 EQ ppl.find(keySmiley Surprisedwner1)) then output;

   if (0 EQ ppl.find(keySmiley Surprisedwnr2)) then output;

run;

Idea Statuses
Top Liked Authors