hash object

Reply
Contributor
Posts: 68

hash object

Hi guys, I copied the code directly from the book. However, it has errors.

Can anyone let me know how to correct the error? Thank you in advance.

CODE:

data work.difference;

   length goalamount 8;

   if _N_=1 then do;

   declare hash goal();

   goal.definekey("QtrNum");

   goal.definedata("GoalAmount");

   goal.definedone( );

call missing(QtrNum,Goalamount);

   goal.add(key:'qtr1',data:10);

   goal.add(key:'qtr2',data:15);

   goal.add(key:'qtr3',data:5);

   goal.add(key:'qtr4',data:15);

end;

   set sasuser.contrib;

   goal.find( );

   Diff=amount-goalamount;

run;

LOG:

18503  data work.difference;
18504   length goalamount 8;
18505   if _N_=1 then do;
18506   declare hash goal();
18507   goal.definekey("QtrNum");
18508   goal.definedata("GoalAmount");
18509   goal.definedone( );
18510   call missing(QtrNum,Goalamount);
18511   goal.add(key:'qtr1',data:10);
18512   goal.add(key:'qtr2',data:15);
18513   goal.add(key:'qtr3',data:5);
18514   goal.add(key:'qtr4',data:15);
18515   end;
18516   set sasuser.contrib;
ERROR: Variable QtrNum has been defined as both character and numeric.
18517   goal.find( );
18518   Diff=amount-goalamount;
18519   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DIFFERENCE may be incomplete.  When this step was stopped there
         were 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds

Respected Advisor
Posts: 3,156

Re: hash object

my previous answer was wrong, try this:

length QtrNum $ 4;

before the call missing statement.

Haikuo

Edit: actually in this case, you don't really need the call missing statement.

Ask a Question
Discussion stats
  • 1 reply
  • 208 views
  • 0 likes
  • 2 in conversation