2016-05-16 8 views
1

私はテキストファイルに以下のようなデータを持っています。テキストファイルを3つのデータセット/テーブルに分割します

テキストファイルを3つのデータセット/テーブルに分割するにはどうすればよいですか?

収益データを含む1、償還データを含む第2、有効期限データを含む第3それらのそれぞれはたくさんの行を持っています、私はちょうどそれらのそれぞれのために3〜4行を述べました。私はInfileステートメントを使用しようとしていますが、分割方法は分かりません。最初に、最初のデータ(earnings)が読み取られ、sasが単語redemptionsを識別するたびに、それを停止して残りのデータを第2のデータセットに移動しなければならず、sasが単語Expirationsを識別するたびに、 3番目のデータセットに移動する必要があります。助言がありますか ?

Earnings 
abc 123 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecekckk 
.... 
redemptions 
abc 123 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecekckk 
Expirations 
abc 123 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecd ccsdc 
djc c djc cjdcjjnc 

答えて

1

保持変数を使用すると、これを達成するのに役立ちます。

以下のコードを使用して、infileステートメントのdatalinesをファイル名に置き換え、正しいinfileパラメータを設定します。

data rawImport; 
    infile datalines dsd delimiter=' ' truncover; 
    informat C1-C4 $32.; 
    input C1-C4; 
    datalines; 
Earnings 
abc 123 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecekckk 
Redemptions 
abc 234 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecekckk 
Expirations 
abc 345 xyz abjjdd 
bhb edw ajd jnjnjknn 
ebc ecc cec cecd ccsdc 
djc c djc cjdcjjnc 
; 

retain変数を使用することで、適切なデータセットにラインをディスパッチできるようになりました。

data Earnings Redemptions Expirations; 
    set rawImport; 
    length outputDS $ 12; 
    retain outputDS; 

    * Determine output dataset; 
    if C1 = "Earnings" then do; 
    outputDS = "Earnings"; 
    delete; 
    end; 
    else if C1 = "Redemptions" then do; 
    outputDS = "Redemptions"; 
    delete; 
    end; 
    else if C1 = "Expirations" then do; 
    outputDS = "Expirations"; 
    delete; 
    end; 

    * output to appropriate dataset; 
    if outputDS = "Earnings" then output Earnings; 
    else if outputDS = "Redemptions" then output Redemptions; 
    else if outputDS = "Expirations" then output Expirations; 

    drop outputDS; 
run; 

ログは今示しています

NOTE: There were 13 observations read from the data set WORK.RAWIMPORT. 
NOTE: The data set WORK.EARNINGS has 3 observations and 4 variables. 
NOTE: The data set WORK.REDEMPTIONS has 3 observations and 4 variables. 
NOTE: The data set WORK.EXPIRATIONS has 4 observations and 4 variables. 
関連する問題