SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 5 replies
  • 1313 views
  • 0 likes
  • 4 in conversation