BookmarkSubscribeRSS Feed
InfoAlisaA
Calcite | Level 5

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

2 REPLIES 2
Patrick
Opal | Level 21

You forgot to set the quotes around the table name

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

Haikuo
Onyx | Level 15

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3360 views
  • 0 likes
  • 3 in conversation