BookmarkSubscribeRSS Feed
astha8882000
Obsidian | Level 7

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';

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

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;
astha8882000
Obsidian | Level 7
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?
Tom
Super User Tom
Super User

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)

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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