ここには、従業員の役職と、その役職がキャリア全体で開始された月と年のリストであるデータセットがあります。次のようになります。employeeIDJobTitle1MonthYearofTitle1Department1 Jobtitle2 MonthYearofTitle2Department2など。
最初のデータセットに含まれておらず、役職と役職の日付が1つしかない従業員の別のリストがあります。私の目標は、役職と月/年に基づいて2番目のデータセットの従業員と1番目のデータセットの従業員を照合することですが、複数の変数の間に情報が存在するため、この照合方法が完全にわかりません。
言い換えると、2017年1月に管理者になったMarySueがいる場合、2017年1月に管理者になったJohnDoeと彼女を照合し、さらに分析するために一致としてフラグを立てます。
残念ながら、コードをどこから始めればよいのかわからないため、試したことはありません。データは次のようになります
データセット1
employeeID JobTitle1 MonthYearofTitle1 Jobtitle2 MonthYearofTitle2
JohnDoe Intern Jan2016 Admin Jan2017
JakeSo VP Jul2017
JulieDo Manager April2017
データセット2
employeeID JobTitle1 MonthYearofTitle1
MarySue Admin Jan2017
JaneDoe Admin Jan2017
Greg VP Jul2017
望ましい結果/データセット:
Employee1 Employee2 Title Date Flag
JohnDoe MarySue Admin Jan2017 Match
JakeSo Greg VP Jul2017 Match
JulieDo Admin Jan2017 No Match
誰か助けてもらえますか?
あなたは行うことができますFULL JOIN
かLeft JOIN
と、使用Case
一致するレコードを示すために、計算フィールドを作成するステートメントを。
以下のコードは、完全結合を実行し、フラグフィールドを作成します。
Table1とTable2の作成:1つのレコードのみが一致します
data table1;
input employeeID $ JobTitle1 $ MonthYearofTitle1 Jobtitle2 $ MonthYearofTitle2 ;
informat MonthYearofTitle1 monyy7. MonthYearofTitle2 monyy7.;
format MonthYearofTitle1 monyy7. MonthYearofTitle2 monyy7.;
datalines;
JohnDoe Intern Jan2016 Admin Jan2017
TomJones Junior Jul2016 Admin Jul2017
;
run;
data table2;
input employeeID $ JobTitle1 $ MonthYearofTitle1 ;
informat MonthYearofTitle1 monyy7.;
format MonthYearofTitle1 monyy7.;
datalines;
MarySue Admin Jan2017
JackieC Admin Jul2013
;
run;
完全参加:すべてのデータを取得するには
proc sql;
create table want as
select
t1.employeeID as t1_employeeID , t2.employeeID as t2_employeeID,
t2.JobTitle1 as t2_JobTitle,
t2.MonthYearofTitle1 as t2_MonthYearofTitle1,
case when
((t1.JobTitle1=t2.JobTitle1 and t1.MonthYearofTitle1=t2.MonthYearofTitle1) or (t1.JobTitle2=t2.JobTitle1 and t1.MonthYearofTitle2=t2.MonthYearofTitle1)) then "Match"
else "No-Match" end as flag
from table1 as t1 full join table2 as t2
on (t1.JobTitle1=t2.JobTitle1 and t1.MonthYearofTitle1=t2.MonthYearofTitle1) or (t1.JobTitle2=t2.JobTitle1 and t1.MonthYearofTitle2=t2.MonthYearofTitle1)
;
quit;
結果:
t1_employeeID=JohnDoe t2_employeeID=MarySue t2_JobTitle=Admin t2_MonthYearofTitle1=JAN2017 flag=Match
t1_employeeID= t2_employeeID=JackieC t2_JobTitle=Admin t2_MonthYearofTitle1=JUL2013 flag=No-Match
t1_employeeID=TomJones t2_employeeID= t2_JobTitle= t2_MonthYearofTitle1=. flag=No-Match
更新:
左結合:テーブル1からレコードのみを取得するには
proc sql;
create table want as
select
t1.employeeID as Employee1 , t2.employeeID as Employee2,
coalescec(t2.JobTitle1,t1.JobTitle2,t1.JobTitle1) as Title,
coalesce(t2.MonthYearofTitle1,t1.MonthYearofTitle2,t1.MonthYearofTitle1) as Date format monyy7.,
case when
((t1.JobTitle1=t2.JobTitle1 and t1.MonthYearofTitle1=t2.MonthYearofTitle1) or (t1.JobTitle2=t2.JobTitle1 and t1.MonthYearofTitle2=t2.MonthYearofTitle1)) then "Match"
else "No-Match" end as Flag
from table1 as t1 left join table2 as t2
on (t1.JobTitle1=t2.JobTitle1 and t1.MonthYearofTitle1=t2.MonthYearofTitle1) or (t1.JobTitle2=t2.JobTitle1 and t1.MonthYearofTitle2=t2.MonthYearofTitle1)
;
quit;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加