Help using Base SAS procedures

Output hash dataset if not found

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Output hash dataset if not found

Hi,

 

I used one dataset as a hash, with "ID" as its key. I also have other variables in the hash that I want to keep and I included them in defineData. 

 

I'd like to output variables in the hash, where the "ID" can not be found in the main dataset, because I'm more interested in variables that dont exist in the main dataset.

 

The codes I'm using now are like this: if hash.find()^=o then output .... But it seems like it outputs variables in the main datasets instead of in the hash.

 

I can't do it by reversing the hash and main dataset, because the main dataset is far larger than my hash. What code should I use to solve it? Any help will be appreciated! 


Accepted Solutions
Solution
‎10-27-2016 01:26 PM
Super User
Posts: 10,041

Re: Output hash dataset if not found

Remove it from Hash when you find it , and at the end of data step output Hash.

 

data _null_;
 set main end=last;
 ...........
 if hash.check()=o then hash.remove();
 if last then hash.output(dataset:'want');
 run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,574

Re: Output hash dataset if not found

In similar situation I prefer the SQL.

Let datasets be: SMALL (instead hash) and BIG with ID common in both, then

 

proc sql;

      create table WANT as select * from BIG

      where ID not in (select ID from SMALL);

quit;

Occasional Contributor
Posts: 5

Re: Output hash dataset if not found

The dataset is really large (more than 400 GB), so I was suggested to use Hash. But thanks for your help!

Solution
‎10-27-2016 01:26 PM
Super User
Posts: 10,041

Re: Output hash dataset if not found

Remove it from Hash when you find it , and at the end of data step output Hash.

 

data _null_;
 set main end=last;
 ...........
 if hash.check()=o then hash.remove();
 if last then hash.output(dataset:'want');
 run;
Occasional Contributor
Posts: 5

Re: Output hash dataset if not found

This works! Thanks!
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 254 views
  • 0 likes
  • 3 in conversation