簡體   English   中英

如何在使用SAS的結果中克服丟失的頻率

[英]How Do I get Ride of the Missing Frequency in my RESULT USING SAS

我對此並不陌生,我已經發布了這個問題。 但是我認為我沒有很好地解釋它。

我在SAS中有一個數據。 一些單元為空,並且在SAS輸出窗口中,單元中具有DOT。 當我運行結果時,在表的末尾,它添加MISSING FREQUENCY = 7或任何數字...

如何使SAS忽略丟失頻率,而僅使用產生結果的頻率...請查看我的屏幕截圖,代碼和我的CSV: 輸出數據

結果是底部的MISSING頻率

/* 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;

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

缺少的數值被認為小於任何實數。 因此,如果您希望使用小於或等於這樣的條件,那么如果您不將其排除在其他條件之外,則會包括缺失值。

您可以在procs上使用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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM