DATA Step, Macro, Functions and more

Merging table - row on colum

Accepted Solution Solved
Reply
Highlighted
Super Contributor
Posts: 402
Accepted Solution

Merging table - row on colum

Hi Everyone,

 

I have the following problem and really cant find a way to deal with it.

 

I have 1 dataset that report working hour for each worker on each project (project_code).

I have 2nd dataset that report the pay rate for each worker on each project. 

 

Now I have to get info of pay rate from the second one to put in the 1st one.

 

Very straightforward but cant do it by now.

 

Any help is very much appreciate.

 

HHC

 


data hour;
input user $ project_code hour_working;
datalines;
harry 160 3
harry 150 8
lucy 220 3
john 120 3
john 110 1
john 100 9
;
run;

data payrate;
input user $ project_code1 rate1 project_code2 rate2 project_code3 rate3;
datalines;
harry 160 300 150 800 . .
lucy 220 300 . . . .
john 120 300 110 100 100 900
xzy 1000 300 . . . . . . ; run;

 


Accepted Solutions
Solution
a week ago
Super User
Posts: 19,171

Re: Merging table - row on colum

Transpose Table2 into a long format and then merge. 

View solution in original post


All Replies
Solution
a week ago
Super User
Posts: 19,171

Re: Merging table - row on colum

Transpose Table2 into a long format and then merge. 

Super Contributor
Posts: 402

Re: Merging table - row on colum

Thank you.

 

HHC

 


data hour;
input user $ project_code hour_working;
datalines;
harry 160 3
harry 150 8
lucy 220 3
john 120 3
john 110 1
john 100 9
;
run;

data hour; set hour; n=_N_;run;

data payrate;
input user $ project_code1 rate1 project_code2 rate2 project_code3 rate3;
datalines;
harry 160 300 150 800 . .
lucy 220 300 . . . .
john 120 300 110 100 100 900xzy 1000 300 . . . . . .
;
run;
proc sort; by user;run;

proc transpose data=payrate out=pay_trans;
by user;run;
data pay_trans; set pay_trans;
drop l:;
rename COL1=rate;
lu=lag(user);
ln=lag(_name_);
lc=lag(COl1);
if user=lu then project_code=lc;run;

data pay_trans; set pay_trans;
drop _NAME_;
if index(_NAME_,"rate")>0; 
if rate=. and project_code=. then delete;
run;

proc sql;
create table Want
as select a.*, b.Rate
from hour as a left join Pay_trans as b
on a.user=b.user and a.project_code=b.project_code; quit;

proc sort data= Want; by n;run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 2 in conversation