Fundamentals of Programming in SAS. James Blum
Identifiable
Output 2.2.2: Minimum, Median, and Maximum on Mortgage Payments Across Multiple Categories
Metro | Household Income | Variable | Label | Minimum | Median | Maximum |
Metro, Inside City | Negative | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 44070000 | 1200250000 | 4500675000 |
$0 to $45K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 740130000 | 68005303000 | |
$45K to $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 1000180000 | 74004915000 | |
Above $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 1600340000 | 74005303000 | |
Metro, Outside City | Negative | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 10010000 | 1450250000 | 54004152000 |
$0 to $45K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 850150000 | 74004304000 | |
$45K to $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 1100199000 | 68004915000 | |
Above $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 1600330000 | 74004915000 | |
Metro, City Status Unknown | Negative | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 18017000 | 1200245000 | 53002948000 |
$0 to $45K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 720125000 | 74004915000 | |
$45K to $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 960160000 | 74004915000 | |
Above $90K | MortgagePaymentHomeValue | Mortgage PaymentHome Value | 1000 | 1400270000 | 74004915000 |
In Outputs 2.2.3 and 2.2.4, frequencies and percentages are summarized across combinations of various categories, which requires mastery of the fundamentals of the FREQ procedure.
Output 2.2.3: Income Status Versus Mortgage Payment
Table of HHIncome by MortgagePayment | |||||
HHIncome(Household Income) | MortgagePayment(Mortgage Payment) | ||||
FrequencyRow Pct | $350 and Below | $351 to $1000 | $1001 to $1600 | Over $1600 | Total |
Negative | 309.93 | 9732.12 | 9230.46 | 8327.48 | 302 |
$0 to $45K | 2292916.37 | 8312559.33 | 2261716.14 | 114368.16 | 140107 |
$45K to $90K | 138776.96 | 10366051.99 | 5477827.48 | 2705213.57 | 199367 |
Above $90K | 59442.89 | 5267925.58 | 6247430.33 | 8486741.20 | 205964 |
Total | 42780 | 239561 | 139961 | 123438 | 545740 |
Output 2.2.4: Income Status Versus Mortgage Payment for Metropolitan Households (Table 1 of 3)
Table 1 of HHIncome by MortgagePayment | |||||
Controlling for Metro=Metro, Inside City | |||||
HHIncome(Household Income) | MortgagePayment(Mortgage Payment) | ||||
FrequencyRow Pct | $350 and Below | $351 to $1000 | $1001 to $1600 | Over $1600 | Total |
Negative | 00.00 | 730.43 | 939.13 | 730.43 | 23 |
$0 to $45K | 159610.75 | 894960.30 | 259717.50 | 170011.45 | 14842 |
$45K to $90K | 9104.75 | 921548.13 | 557129.10 | 345018.02 | 19146 |
Above $90K | 5042.29 | 494722.46 | 632128.70 | 1025646.56 | 22028 |
Total | 3010 | 23118 | 14498 | 15413 | 56039 |
2.3 Getting Started with Data Exploration in SAS
This section reviews and extends some fundamental SAS concepts demonstrated in code supplied for Chapter 1, with these examples built upon a simplified version of the case study data. First, Program 2.3.1 uses the CONTENTS and PRINT procedures to make an initial exploration of the Ipums2005Mini data set. To begin, make sure the BookData library is assigned as done in Chapter 1.
Program 2.3.1: Using the CONTENTS and PRINT Procedures to View Data and Attributes
proc contents data=bookdata.ipums2005mini;
ods select variables;
run;
proc print data=bookdata.ipums2005mini(obs=5);
var state MortgageStatus MortgagePayment HomeValue Metro;
run;
The BookData.Ipums2005Mini data set is a modification of a data set used later in this chapter, BookData.Ipums2005Basic. It subsets the original data set down to a few records and is used for illustration of these initial concepts.
The ODS SELECT statement limits the output of a given procedure to the chosen tables, with the Variables table from PROC CONTENTS containing the names and attributes of the variables in the chosen data set. Look back to Program 1.4.4, paying attention to the ODS TRACE statement and its results, to review how this choice is made.
The OBS= data set option limits the number of observations processed by the procedure. It is in place here simply to limit the size of the table shown in Output 2.3.1B. At various times in this text, the output shown may be limited in scope; however, the code given may not include this option for all such cases.
The VAR statement is used in the PRINT procedure to select the variables to be shown and the column order in which they appear.
Output 2.3.1A: Using the CONTENTS Procedure to View Attributes
Alphabetic List of Variables and Attributes | ||||
# | Variable | Type | Len | Format |
4 | CITYPOP | Num | 8 | |
2 | COUNTYFIPS | Num | 8 | |
10 | City | Char | 43 | |
6 | HHINCOME | Num | 8 | |
7 | HomeValue | Num | 8 | |
3 | METRO | Num | 8 | BEST12. |
5 | MortgagePayment | Num | 8 | |
9 | MortgageStatus | Char | 45 | |
11 | Ownership | Char | 6 | |
1 | SERIAL | Num | 8 | |
8 | state | Char | 57 |
Output 2.3.1B: Using the PRINT Procedure to View Data
Obs | state | MortgageStatus | MortgagePayment | HomeValue | METRO |
1 | South Carolina | Yes, mortgaged/ deed of trust or similar debt | 200 | 32500 | 4 |
2 | North Carolina | No, owned free and clear | 0 | 5000 | 1 |
3 | South Carolina | Yes, mortgaged/ deed of trust or similar debt | 360 | 75000 | 4 |
4 | South Carolina | Yes, contract to purchase | 430 | 22500 | 3 |
5 | North Carolina | Yes, mortgaged/ deed of trust or similar debt | 450 | 65000 | 4 |
2.3.1 Assigning Labels and Using SAS Formats
As seen in Chapter 1, SAS variable names have a certain set of restrictions they must meet, including no special characters other than an underscore. This potentially limits the quality of the display for items such as the headers in PROC PRINT. SAS does permit the assignment of labels to variables, substituting more descriptive text into the output in place of the variable name, as demonstrated in Program 2.3.2.
Program 2.3.2: Assigning Labels
proc print data=bookdata.ipums2005mini(obs=5) noobs label;