Help using Base SAS procedures

Need a Hash Code Check

Reply
Frequent Contributor
Posts: 90

Need a Hash Code Check

Hello Everyone,

I was wondering if someone could check my code for me.

This is my code:

data temp;

   do I=1 to 1000;

      do J=1 to 1000;

         do Name='Mary','Sue','Bob','Ted';

            output;

         end;

      end;

   end;

run;

data hash_sort (keep=Name I J);

length Name $4 I 8. J 8.;

  if _N_=1 then do;

  if 0 then set temp (keep=Name I J);

  declare hash hs(dataset:temp, ordered:'a');

  hs.definekey('Name');

  hs.definedata('Name','I','J');

  hs.definedone();

  call missing(Name);

end;

stop;

run;

My log keeps saying:

ERROR: Type mismatch for method parameter 1 at line 743 column 18.

ERROR: Expecting Character type.

ERROR: DATA STEP Component Object failure.  Aborted during the EXECUTION phase.

Could someone let me know where I am going wrong with my code?

Thanks,

Alisa

Respected Advisor
Posts: 3,886

Re: Need a Hash Code Check

You forgot to set the quotes around the table name

declare hash hs(dataset:'temp', ordered:'a');

Respected Advisor
Posts: 3,124

Re: Need a Hash Code Check

Hi Alisa,

I am not sure about the purpose of your code, the only hint came from the data set name 'hash_sort', so I will just assume that you want your new table sorted by 'name'.

Let 's just use Ksharp's approach:

data _null_ ;

  if _N_=1 then do;

  if 0 then set temp;

  declare hash hs(dataset:'temp', ordered:'a', multidata:'y');

  hs.definekey('Name');

  hs.definedata(all:'y');

  hs.definedone();

end;

hs.output(dataset:'hash_sort');

run;

Note: 1. The dataset name 'temp' in the hash definition needs to be quoted. 2. Since key 'name' is not unique index, multidata option needs to be specified. 3. You could defined a hiter to read in the records one by one, but again, it would not be recommended. 4. since you already have 'if 0 then set', so you would not need call missing() and length statement.

Regards,

Haikuo

Ask a Question
Discussion stats
  • 2 replies
  • 540 views
  • 0 likes
  • 3 in conversation