troubleshooting Question

SAS Data Sets Manipulations

Avatar of labradorchik
labradorchikFlag for United States of America asked on
Programming Languages-OtherDatabasesProgramming
5 Comments1 Solution626 ViewsLast Modified:
I am trying to do some matching of data on a few different variables from two datasets.
Input Files
Data1.sas7bdat has variables: Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8, and Var9.
Data2.sas7bdat has variables: Var10, Var11, Var12, and Var13.

Output Files
Data3.sas7bdat  
Counts.log will have all counts for variables:  Var10a, Var10b, Var10c, + input Data1 counts and output Data3 counts.


I am trying to read Data1 data set and output all records to Data3 data set with Var10a, Var10b, and Var10c by using Var10 from Data2.
Here is the process of creation Data3:
1.      Look up Var10 from Data2 and call it Var10a. Use Var1, Var2, Var3 from Data1 to match records value for variables Var11, Var12, and Var13 in the Data2.
2.       Look up Var10 from Data2 and call it Var10b. Use Var4, Var5, Var6 from Data1 to match records value for variables Var11, Var12, and Var13 in the Data2.
3.      Look up Var10 from Data2 and call it Var10c. Use Var7, Var8, Var9 from Data1 to match records value for variables Var11, Var12, and Var13 in the Data2.
4.      Then I need to choose between Var10 values as following:
 if Var10a ne blank, then Var10 = Var10a
else if Var10b ne blank, Var10 = Var10b
else if Var10c ne blank, Var10 = Var10c
else Var10 = blank

5.      Count how many times Var10 was assigned from Var10a, Var10b, and Var10c and write into Counts.Log .
6.      Count all input and output records and write into Counts.Log
Note: values in variables Var11, Var12, and Var13 from Data2 have similar values as these 3 sets of variables in Data1:  
set 1 (Var1, Var2, Var3)
set2 (Var4, Var5, Var6)
set3 (Var7, Var8, Var9)

This is how I started, but I am not sure how should I proceed next to match my data from both datasets??  Any help will be greatly appreciated!  Thank you!

data Data3;
 set Data1 end=last;






  
  if last then do;
   file 'Counts' mod;               
    put ' '; 
    put '*****************************************************************';
    put '* Total Input Records                        ' _n_;
    put '* Total Output Records                       ' outrec; 
    put '*  Total Var10s came from Var10a             ' acnt;
    put '*  Total Var10s came from Var10b             ' bcnt;
    put '*  Total Var10s came from Var10c             ' ccnt;
    put '*****************************************************************';
    put ' ';
  end;  
run;
ASKER CERTIFIED SOLUTION
theartfuldazzler

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros