BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Transpose Table2 into a long format and then merge. 

View solution in original post

2 REPLIES 2
Reeza
Super User

Transpose Table2 into a long format and then merge. 

hhchenfx
Barite | Level 11

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;

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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