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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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