2017-07-19 44 views
0

我是新手,我已經發布了這個問題。但我想我沒有解釋得很好。如何在我的結果中使用SAS獲得遺漏頻率

我在SAS裏有一個DATA。 某些單元格爲空[無],並且在SAS輸出窗口中,單元格中有一個DOT。 當我運行結果,在表的末尾,它添加MISSING FREQUENCY = 7或任何數字...

如何使SAS忽略缺失頻率並只使用有結果的那個。 .. 請參閱我的屏幕截圖,代碼和我的CSV:OUTPUT DATA

RESULT WITH the MISSING frequency at the bottom

/* Generated Code (IMPORT) */ 
/* Source File:2012_16_ChathamPed.csv */ 
/* Source Path: /home/cwacta0/my_courses/Week2/ACCIDENTS */ 
PROC IMPORT 
     DATAFILE='/home/cwacta0/my_courses/Week2/ACCIDENTS/2012_16_ChathamPed.csv' 
     OUT=imported REPLACE; 
    GETNAMES=YES; 
    GUESSINGROWS=32767; 
RUN; 

proc contents data=work.imported; 
run; 

libname mydata"/courses/d1406ae5ba27fe300" access=readonly; 
run; 

/* sorting data by location*/ 
PROC SORT ; 
    by LocationOfimpact; 
    LABEL Route="STREET NAME" Fatalities="FATALITIES" Injuries="INJURIES" 
     SeriousInjuries="SERIOUS INJURIES" LocationOfimpact="LOCATION OF IMPACT" 
     MannerOfCollision="MANNER OF COLLISION" 
     U1Factors="PRIMARY CAUSES OF ACCIDENT" 
     U1TrafficControl="TRAFFIC CONTROL SIGNS AT THE LOCATION" 
     U2Factors="SECONDARY CAUSES OF ACCIDENT" 
     U2TrafficControl="OTHER TRAFFIC CONTROL SIGNS AT THE LOCATION" 
     Light="TYPE OF LIGHTHING AT THE TIME OF THE ACCIDENT" 
     DriverAge1="AGE OF THE DRIVER" DriverAge2="AGE OF THE CYCLIST"; 

    /* Here I was unable to extract the drivers age 25 or less and te drivers who disregarded stop sign. here is how I coded it; 
    IF DriverAge1 LE 25; 
    IF U1Factors="Failed to Yield" OR U1Factors= "Disregard Stop Sign"; 
    Run; 

    Also, I want to remove the Missing DATA under the results. But in the data, those are just a blank cell. How do I tell SAS to disregard a blank cell and not add it to the result? 
    Here is what I did and it does not work... 

    if U1Factors="BLANK" Then U1Factors="."; 
    Please help me figre this out...Tks 

    IF U1Factors="." Then call missing(U1Factors)*/; 

Data want; 
    set imported; 

    IF DriverAge1 LE 25 And U1Factors in ("Failed to Yield", "Wrong Side of Road", 
     "Inattentive"); 

    IF Light in ("DarkLighted", "DarkNot Lighted", "Dawn"); 
run; 

proc freq ; 
    tables /*Route Fatalities Injuries SeriousInjuries LocationOfimpact MannerOfCollision*/ 
    U1Factors /*U1TrafficControl U2Factors U2TrafficControl*/ 
    light DriverAge1 DriverAge2; 
RUN; 
+0

您還沒有顯示你想要的結果。我會推薦帖子。 – Reeza

+0

爲什麼在PROC SORT和DATA步驟之間有IF語句? – Tom

回答

0

SAS將顯示缺少使用期數值變量。因此,如果CSV文件中DriverAge1的列沒有任何內容,那麼該觀察值將會缺失值。如果您的變量是字符,那麼SAS通常也會將輸入流中的一個句點值轉換爲SAS變量中的空格。

缺少的數字值被認爲小於任何實數。因此,如果您希望使用小於或等於的條件,那麼如果您不排除某些其他條件,則會包含缺少的值。

您可以在過程中使用WHERE語句來過濾數據。如果要在單獨的語句中追加WHERE條件,則可以使用WHERE ALSO語法添加額外條件。

如果您希望在PROC FREQ輸出中顯示缺少的類別,請將MISSPRINT選項添加到TABLES語句。或者添加MISSING選項,它會出現並且也會被統計。

proc freq ; 
    where . < DriverAge1 <= 25 
    and U1Factors in ("Failed to Yield", "Wrong Side of Road","Inattentive") 
    ; 
    where also Light in ("DarkLighted", "DarkNot Lighted", "Dawn"); 
    tables U1Factors light DriverAge1 DriverAge2/missing; 
run; 

WHERE條件將應用於整個數據集。所以,如果您排除失蹤DriverAge1和失蹤U1Factors

proc freq ; 
    where not missing(U1Factors) and not missing(DriverAge1); 
    tables U1Factors DriverAge1 ; 
run; 

那麼只有不會錯過兩個觀測將包括在內。因此,您可能需要爲每個變量分別生成統計信息。

proc freq ; 
    where not missing(U1Factors); 
    tables U1Factors ; 
run; 
proc freq ; 
    where not missing(DriverAge1); 
    tables DriverAge1 ; 
run; 
+0

謝謝湯姆。使感官.. –

相關問題