我試圖創建SAS新的變量,有下面的代碼:重疊範圍SAS
if (Age >= 16) and (Age <= 85) then Age_New = "Total, 16 years and over";
else if (Age >= 16) and (Age <= 19) then Age_New = "16 to 19 years";
else if (Age >= 20) and (Age <= 85) then Age_New = "20 years and over";
else if (Age >= 20) and (Age <= 24) then Age_New = "20 to 24 years";
else if (Age >= 25) and (Age <= 85) then Age_New = "25 years and over";
else if (Age >= 25) and (Age <= 54) then Age_New = "25 to 54 years";
else if (Age >= 55) and (Age <= 85) then Age_New = "55 years and over";
else if (Age >= 55) and (Age <= 64) then Age_New = "55 to 64 years";
else if (Age >= 65) and (Age <= 85) then Age_New = "65 years and over";
else Age_New = "Other";
現在是什麼情況持續發生的是,我得到的價值「總計,年滿16週歲」的所有觀察和我理解爲什麼。我如何編輯代碼來完成我想要實現的任務?
我認爲你的目標是重疊組的總結。使用IF語句(sans ELSE),您需要輸出每個命中的觀察值。那麼DO:AGE_NEW = ...;輸出;結束爲了使它工作,你還需要刪除ELSE部分。 SAS有一個很好的功能,可以使這更容易稱爲「多標籤格式」。您不需要新變量或製作任何觀察值。轉到PROC FORMAT並閱讀它,然後查看PROC MEANS/SUMMARY或TABULATE中的示例以瞭解如何使用它。 –
我其實知道prof格式選項,但實際上我需要爲這個新變量創建一個新的數據集用於其他目的。 – user2916331
你看起來像你要求一個變量有兩個值。這是不可能的......除非你使用MLF,不管怎麼說,正如DN注意到的那樣。你究竟在做什麼(這實際上是可能的)? – Joe