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;
Transpose Table2 into a long format and then merge.
Transpose Table2 into a long format and then merge.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.