Fundamentals of Programming in SAS. James Blum

Чтение книги онлайн.

Читать онлайн книгу Fundamentals of Programming in SAS - James Blum страница 25

Автор:
Жанр:
Серия:
Издательство:
Fundamentals of Programming in SAS - James Blum

Скачать книгу

data=BookData.IPUMS2005Basic;

      table Metro*MortgagePayment / nocol nopercent format=comma10.;

      format Metro Metro. MortgagePayment Mort.;

      run;

       NOCOL and NOPERCENT suppress the column and overall percentages, respectively, with NOPERCENT also applying to the marginal totals. NOROW and NOFREQ are also available, with NOFREQ also applying to the marginal totals.

       A format can be applied to the frequency statistic; however, this only applies to cross-tabular frequency tables and has no effect in one-way tables.

      Output 2.7.5: Using Options in the TABLE Statement

Table of METRO by MortgagePayment
METRO(Metropolitan status)MortgagePayment(First mortgage monthly payment)
FrequencyRow PctNone$350 and Below$351 to $1000$1001 to $1600Over $1600Total
Not Identifiable49,37953.666,9797.5825,48827.707,3077.942,8753.1292,028
Not in Metro Area134,31458.2021,6989.4060,94826.4110,4644.533,3511.45230,775
Metro, Inside City96,48762.504,4102.8628,86618.7014,0499.1010,5566.84154,368
Metro, Outside City149,96143.9812,1483.5679,38823.2856,33016.5243,15512.66340,982
Metro, City Status Unknown173,55050.9114,6214.2988,42125.9440,65111.9223,6666.94340,909
Total603,69159,856283,111128,80183,6031,159,062

      Higher dimensional requests can be made; however, they are constructed as a series of two-dimensional tables. Therefore, a request of A*B*C in the TABLE statement creates the B*C table for each level of A, while a request of A*B*C*D makes the C*D table for each combination of A and B, and so forth. Program 2.7.6 generates a three-way table, where a cross-tabulation of Metro and HomeValue is built for each level of Mortgage Status as shown in Output 2.7.6. The VALUE statement that defines the character format $MortStatus takes advantage of the fact that value ranges are legal for character variables. Be sure to understand the difference between uppercase and lowercase letters when ordering the values of a character variable.

      Program 2.7.6: A Three-Way Table in PROC FREQ

      proc format;

      value MetroB

      0 = “Not Identifiable”

      1 = “Not in Metro Area”

      other = “In a Metro Area”

      ;

      value $MortStatus

      ‘No’-’Nz’=’No’

      ‘Yes’-’Yz’=’Yes’

      ;

      value Hvalue

      0-65000=’$65,000 and Below’

      65000<-110000=’$65,001 to $110,000’

      110000<-225000=’$110,001 to $225,000’

      225000<-500000=’$225,001 to $500,000’

      500000-high=’Above $500,000’

      ;

      run;

      proc freq data=BookData.IPUMS2005Basic;

      table MortgageStatus*Metro*HomeValue/nocol nopercent format=comma10.;

      format MortgageStatus $MortStatus. Metro MetroB. HomeValue Hvalue.;

      where MortgageStatus ne ‘N/A’;

      run;

      Output 2.7.6: A Three-Way Table in PROC FREQ

Table 1 of METRO by HomeValue
Controlling for MortgageStatus=No
METRO(Metropolitan status)HomeValue(House value)
FrequencyRow Pct$65,000 and Below$65,001 to $110,000$110,001 to $225,000$225,001 to $500,000Above $500,000Total
Not Identifiable10,77735.495,46017.9810,41534.292,5848.511,1343.7330,370
Not in Metro Area34,76640.5716,26118.9826,88931.385,5536.482,2272.6085,696
In a Metro Area34,17618.5523,70612.8671,13338.6033,59018.2321,67811.76184,283
Total79,71945,427108,43741,72725,039300,349
Table 2 of METRO by HomeValue
Controlling for MortgageStatus=Yes
METRO(Metropolitan status)HomeValue(House value)
FrequencyRow Pct$65,000 and Below$65,001 to $110,000$110,001 to $225,000$225,001 to $500,000Above $500,000Total
Not Identifiable7,48617.557,14216.7519,45345.616,46815.172,1004.9242,649
Not in Metro Area24,44325.3419,39620.1140,66842.169,1649.502,7902.8996,461
In a Metro Area26,3516.3337,3458.97175,48242.16110,41226.5266,67116.02416,261
Total58,28063,883235,603126,04471,561555,371

      It is also possible for the FREQ procedure to count based on a quantitative variable using the WEIGHT statement, effectively tabulating the sum of the weights. Program 2.7.7 uses the weight statement to summarize total HomeValue for combinations of Metro and MortgagePayment.

      Program 2.7.7: Using the WEIGHT Statement to Summarize a Quantitative Value.

      proc freq data=BookData.IPUMS2005Basic;

      table Metro*MortgagePayment /nocol nopercent format=dollar14.;

      weight HomeValue;

      format Metro MetroB. MortgagePayment Mort.;

      run;

      Output 2.7.7: Using the WEIGHT Statement to Summarize a Quantitative Value

Table of HomeValue by METRO
HomeValue(House value)METRO(Metropolitan status)
FrequencyRow PctNot IdentifiableNot in Metro AreaIn a Metro AreaTotal
$65,000 and Below$2,737,53012.20$8,736,98638.93$10,969,60048.88$22,444,116
$65,001 to $110,000$3,770,84010.74$9,887,45428.16$21,448,05261.09$35,106,346
$110,001 to $225,000$15,896,8547.82$30,632,55615.07$156,700,07477.10$203,229,484
$225,001 to $500,000$8,192,9084.80$10,741,2586.30$151,601,29488.90$170,535,460
Above $500,000$3,854,2802.60$4,735,2883.19$139,862,78094.21$148,452,348
Total$34,452,412$64,733,542$480,581,800$579,767,754

      Often data is not available as a SAS data set; in practice, data often comes from external sources including raw files such as text files, spreadsheets such as Microsoft Excel ®, or relational databases such

Скачать книгу