- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the format approach I gave you in https://communities.sas.com/t5/SAS-Programming/Hash-or-Array-solution/m-p/489950
It only needs one pass through the large dataset, so it's best performance- and resourcewise. And easier to understand and maintain than a hash.