Hash Object Code Question

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Hash Object Code Question

Hi All,

 

Would someone please explain how the missing records section work? Thank you for your help.

 

 

declare hash hct(dataset: 'work.etls_compare_digest', hashexp: 10);
hct.defineKey("sourcedb_id", "case_id");
hct.defineData("sourcedb_id", "case_id", "compare_digest");
hct.defineDone();
end;

set work.W1PAEO8L end = eof;

/* create digest - version 2.1 */
source_digest = put(md5(catq(' ', contact_id, subject_id, owner_id, owner_name, case_name, Season,
case_priority, case_notes, case_state_code, case_status_code,
case_status_desc)), $hex32.);

/* source/compare match */
if hct.find() eq 0 then
do;
/* source/compare match: Unchanged records */
if source_digest eq compare_digest then
output work.WGK73ZRO;

/* source/compare match: Changed records */
else if source_digest ne compare_digest then
output work.WGK73X4D;

/* remove found key + data */
hct.remove();
end;
/* source table: New records */
else if hct.find() ne 0 then
output work.WGK73YG2;

/* Missing records */
if eof then
rc = hct.output(dataset: 'work.WGK7411D(drop = compare_digest)');


Accepted Solutions
Solution
‎04-10-2017 05:15 PM
Super User
Super User
Posts: 6,318

Re: Hash Object Code Question

You told SAS to set a flag when your were reading the last observation in your SET statement.

set work.W1PAEO8L end = eof;

Then when you get to the last observation you write out the remain records from the hash object. You ave added dataset options to drop one of the variables.

if eof then
  rc = hct.output(dataset: 'work.WGK7411D(drop = compare_digest)')
;

View solution in original post


All Replies
Solution
‎04-10-2017 05:15 PM
Super User
Super User
Posts: 6,318

Re: Hash Object Code Question

You told SAS to set a flag when your were reading the last observation in your SET statement.

set work.W1PAEO8L end = eof;

Then when you get to the last observation you write out the remain records from the hash object. You ave added dataset options to drop one of the variables.

if eof then
  rc = hct.output(dataset: 'work.WGK7411D(drop = compare_digest)')
;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 115 views
  • 1 like
  • 2 in conversation