作者zennage (為什麼)
站內Statistics
標題Re: [程式] SAS的資料處理問題
時間Sun Sep 2 22:46:09 2012
※ 引述《koalababy802 (koala)》之銘言:
: Industry為用戶編號,num為行業代碼。
: 我有兩個檔案,第一個檔案擁有用戶編號以及行業代碼,第二個檔案因為不存在行業代碼
: ,但之後分組會使用到,所以我想要由第一個檔案中抓取。
: 目前的想法是將兩個檔案合併,再用lag的方式抓取,但是似乎沒用,
: 而且有些資料必須lag許多期,此法似乎不可行。
: 想請問板上大大,該如何從我的檔案一來抓取相對應的行業代碼至檔案二呢?謝謝。
: 以下為資料所擷取的一部份
: <檔案一> <檔案二> <檔案二>
: Industry1 Num1 Industry2 Industry2 Num2
: E0003 I551 E0003 E0003 I551
: E0005 Q862 E0005 E0005 Q862
: E0007 Q861 E0007 E0007 Q861
: E0008 O831 E0008 E0008 O831
: E0012 K652 E0012 E0012 K652
: E0013 I551 E0013 E0013 I551
: E0018 K641 E0015 E0015
: E0020 H541 E0017 想將檔案二變成 E0017
: E0024 K641 E0018 = = = = = > E0018 K641
: E0026 G471 E0020 E0020 H541
: E0028 L681 E0020 E0020 H541
: E0031 L681 E0020 E0020 H541
: E0035 J610 E0020 E0020 H541
: E0036 P855 E0024 E0024 K641
: E0041 G471 E0026 E0026 G471
: E0041 G471 E0028 E0028 L681
: E0047 G471 E0031 E0031 L681
: E0048 G471 E0035 E0035 J610
用rename的方式換一下,獻醜了
temp3 的資料會是你要的格式
data temp;
input Industry1$ Num1$ ;
cards;
E0003 I551
E0005 Q862
E0007 Q861
E0008 O831
E0012 K652
E0013 I551
E0018 K641
E0020 H541
E0024 K641
E0026 G471
E0028 L681
E0031 L681
E0035 J610
E0036 P855
E0041 G471
E0041 G471
E0047 G471
E0048 G471
;
proc sort; by Industry1;
run;
data temp1;
input Industry2$;
cards;
E0003
E0005
E0007
E0008
E0012
E0013
E0015
E0017
E0018
E0020
E0020
E0020
E0020
E0024
E0026
E0028
E0031
E0035
;
run;
data temp2;set temp1;rename Industry2=Industry1;proc sort;by Industry1;run;
data temp3;merge temp2 temp;by Industry1;rename Industry1=Industry2;run;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.192.5.131
1F:推 koalababy802:非常感激,試出來了^_^ 09/05 23:23