2016-11-02 11 views
0

各都市の連結コードリストに文字列変数 "zip"を組み合わせたzipcodes変数を作成する必要があります。ここで私がこれまで持っているものです。SASの圧縮データセットに連結コードリストを作成する

data work.zip (drop=estimated_population zip); 
    set work.clean; 
    by state primary_city; 
    length zipcodes $200; 
    retain zipcodes; 
    if first.primary_city then do; 
    estcitpop=0; 
    zipcodes= zip; 
    end; 
    else 
    zipcodes=cats(zipcodes, ',', zip); 
    estcitpop+estimated_population; 
    if last.primary_city; 
run; 

これは私が右の結果取得しますが、それを行うには良い方法はありますか?

ジップは文字の値であり、そのように留まる必要があります。たとえば、ヒューストン市の場合、12345、11345、11145、および11115の郵便番号がある場合は、「12345,11345,11145,11115」と読むために郵便番号が必要です。

答えて

1

よく見えます。私はCATX()関数とDOWループを使って簡単にします。

data work.zip ; 
    do until (last.primary_city); 
    set work.clean; 
    by state primary_city; 
    length zipcodes $200; 
    zipcodes=catx(',',zipcodes, zip); 
    estcitpop=sum(estcitpop,estimated_population); 
    end; 
    drop estimated_population zip; 
run; 
関連する問題