DATA Step, Macro, Functions and more

Replacing hash table

Reply
Contributor
Posts: 42

Replacing hash table

[ Edited ]

Hello,

 

I have a reference code and I want to remove hash table out of it since I'm new to SAS and it is adding a lot of complication and errors when I run the code with it. Here is a sample of what I'm doing:

 

assuming dataset ‘ds1’ looks like the following:

phonenoaccnoamtcustnodda
1234567601102345676011065463454646328
12345676022123456760120005458769646328
123456760332234567601456856534587634646328
1234567604432345676015858345453469646328
123456760554234567601565673499646328
1234567606652345676015753279769646328
12345676077623456760145324646239646328
123456760887234567601451216789646328
1234567609982345676014543287696463458
123456761099234567601452332134219869646328

 

My code:

 

data ds2;

if _n_=1 then do;

dcl hash hh (dataset: 'ds1');

hh.definekey ('phoneno');

hh.definedone();

end;

keep address zip phoneno dda tdda;

%INCLUDE INCLF(f1.sas);  //code for f1 provided below                                                                                                      

 if hh.find()=0;                                                                                                                 

%INCLUDE INCLF(f2.sas); //code for f2 provided below                                                                                                      

Run;

 

F1 code:

Attrib

FILEDATE; –this is a variable in ds3

Set ds3 end=eof;  

IF CUBL > 000  –this is a variable in ds3

     AND DDA NOT IN ('28378','657479') ;                                                  

Keep _All_ ;        

 

F2 code:

Length TDDA $ 1;                                                           

  If DDA in (‘99646328’ ‘9964632823)Then                                                                 

    TDDA = 'Y';                                                               

  Else                                                                         

    TDDA = 'N';

 

 

Super User
Super User
Posts: 8,083

Re: Replacing hash table

Posted in reply to astha8882000

Why not just do this?

proc sql ;
create table ds2 as
select
  address
, zip
, phoneno
, dda
, case when DDA in ('99646328' '9964632823') then 'Y' else 'N' end as tdda
, *
from ds3
where cubl > 0
  and dda not in ('28378' '657479')
  and phoneno in (select phoneno from ds1)
;
quit;
Contributor
Posts: 42

Re: Replacing hash table

Thank you! Based on both of these codes I have a question

As per my code, F2 should be run only when hh.find()=0, this condition is replaced by what in your code?
Super User
Super User
Posts: 8,083

Re: Replacing hash table

[ Edited ]
Posted in reply to astha8882000

Your original data step is using a subsetting IF statement. So it is only keeping the observations where the phone number is found.

So this part of the WHERE clause implements that condition.

 

AND phoneno in (select phoneno from ds1)

Ask a Question
Discussion stats
  • 3 replies
  • 55 views
  • 0 likes
  • 2 in conversation