BookmarkSubscribeRSS Feed
AshokD
Obsidian | Level 7

Hi All,

 

I need some guidelines to proceed with my requirement. Here are the details:-

 

#1)  I have a input txt file data as below:-

Row1 -->123456 Transact1 Transact2 Transact3

Row2--> 456789 Transac1  Transact2

 

 

 

#2) I have queried from database and created another dataset 'Details' with below values:-

TransactionType  Service   

Transact1                A1        

Transact2                A2

Transact3               A1

 

 

I have to compare  #1 and #2 datasets to determine the Service for each transactions for the employee

 

Once we determined the service ,I have to output the data to different fles:-

If service is A1 then output to File1

If service is A2 then output to File2

 

Could you please someone guide me on the SAS Hash Logic functionality for this requirement ?

 

Thanks in advance for your help .

5 REPLIES 5
Reeza
Super User

Can you show what you've tried so far?

And provide sample data?

 

There's a tutorial here on Hash and you can find many more on lexjansen.com

https://www.lexjansen.com/pharmasug/2011/TT/PharmaSUG-2011-TT15.pdf

 

 

AshokD
Obsidian | Level 7

Hi @Reeza

 

Here are the details:-

 

 

Dataset A:-

EmployeeID  Transactiontype

123456             Transact1

345678             Transact2

678903             Transact3

 

Dataset B:-

EmployeeID TransactionType  Service   

123456             Transact1                A1        

345678             Transact2                A2

678903             Transact3               A1

 

I have to compare  A and B datasets to determine the Service for each transactions for the employeeIDs. 

 

 

Once we determined the service ,I have to output the data to different fles:-

If service is A1 then output to File1

If service is A2 then output to File2

 

The Logic I have tried it:-

 

data FILE1 FILE2;

if _N_ = 1 then do;

declare hash h(dataset: "B")

h.defineKey('EmployeeID');
h.defineData('TransactionType','Service ');
h.defineDone();

end;


set A;
rc = h.find();
if (rc = 0) then do;
if Service ='A1' then output FILE1;
else if Service ='A2' then output FILE2;
end;
run;

 

Please have look , correct me if I am wrong anywhere.

 

 

 

PeterClemmensen
Tourmaline | Level 20

What defines an employee? Do you need help importing the .txt file into SAS?

 

Please be more specific about what you want your desired result to look like.

AshokD
Obsidian | Level 7

Hi @PeterClemmensen,

 

Here are the details:-

 

 

Dataset A:-

EmployeeID  Transactiontype

123456             Transact1

345678             Transact2

678903             Transact3

 

Dataset B:-

EmployeeID TransactionType  Service   

123456             Transact1                A1        

345678             Transact2                A2

678903             Transact3               A1

 

I have to compare  A and B datasets to determine the Service for each transactions for the employeeIDs. 

 

 

Once we determined the service ,I have to output the data to different fles:-

If service is A1 then output to File1

If service is A2 then output to File2

 

The Logic I have tried it:-

 

data FILE1 FILE2;

if _N_ = 1 then do;

declare hash h(dataset: "B")

h.defineKey('EmployeeID');
h.defineData('TransactionType','Service ');
h.defineDone();

end;


set A;
rc = h.find();
if (rc = 0) then do;
if Service ='A1' then output FILE1;
else if Service ='A2' then output FILE2;
end;
run;

 

Please have a look , provide your suggestion

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 964 views
  • 0 likes
  • 4 in conversation