Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Problems

1-1.Write a program to read the raw data stored in an external file called VITAL (shown below), and create a SAS System data set called VSIGNS. VITAL contains the following variables, in the order listed: ID, HR (heart rate), SBP (systolic blood pressure), and DBP (diastolic blood pressure).
external file VITAL

A1 68 130 80
B3 101 148 86
C2 . . 72
D1 72 140 88

1-2.Redo problem 1-1 to read the comma-delimited raw data file VITALC shown below:
external file VITALC

A1,68,130,80
B3,101, 148,86
C2,.,.,72
D1, 72, 140 , 88

1-3.Given the raw data lines below, write a program to read these data and create a SAS data set called COLLEGE. The values are separated by one or more spaces, and they represent NAME, TITLE, TENURE (Y or N), and NUMBER (number of classes taught). Notice that some of the names are more than eight characters long.
Sample data for Problem 1–3

Stevenson Ph.D. Y 2
Smith Ph.D. N 3
Goldstein M.D. Y 1

1-4.This example is similar to Problem 1-3 except the values for NAME may include a single blank. The name is separated from the other values by at least two blanks. Modify the program to take this into account. Some sample data are shown below:
Sample data for Problem 1–4

George Stevenson Ph.D. Y 2
Fred Smith Ph.D. N 3
Alissa Goldstein M.D. Y 1

1-5.Given the raw data file description below, write a program to read this data file. Use starting and ending columns. Create a SAS data set called RESPOND. Use an INFORMAT statement if needed. A sample set of data is shown for you to use to test your program.
           File FIRE

Variable     Starting  Ending
 Name         Column   Column  Format    Description
----------------------------------------------------------
CALL_NO         1         3    Numeric   Call number
DATE            5        12    MM/DD/YY  Date of service
TRUCKS          14       15    Numeric   Number of trucks
ALARM           17       17    Numeric   Number of alarms

Sample data (in file FIRE)

001 10/21/94 03 2
002 10/23/94 01 1
003 11/01/94 11 3

1-6.Given the raw data file description below and the same sample data as in Problem 1-5, write a SAS System DATA step to read this data file, and create a SAS data set called RESPOND. Use formatted input; do not use ending columns.
           File FIRE

Variable     Starting
 Name         Column    Length  Format    Description
----------------------------------------------------------
CALL_NO         1          3    Numeric   Call number
DATE            5          8    MM/DD/YY  Date of service
TRUCKS          14         2    Numeric   Number of trucks
ALARM           17         1    Numeric   Number of alarms

1-7.A data file contains a seven-character ID, a quantity, and a price. The first two characters of the ID represent a factory number, and the last two characters represent state abbreviations. The column specifications and some sample data values are shown. Write a program to read these data instream and produce a SAS data set called FACTORY.
                  File Inventory

Variable     Starting
 Name         Column     Length   Format
-------------------------------------------------
    ID             1       7      Character
 QUANTITY          8       2      Numeric
  PRICE           10       7      Numeric (contains
                                  dollar sign and comma)

13AB2NY44   $123
22XXXCT88 $1,033
37123TX11$22,999

Hint: Use the DOLLAR7. informat to read PRICE.

1-8.You have a Social Security number in columns 1-11 of a file, followed by one space, followed by ten 3-digit scores. Using a variable list and an informat list, write a SAS program to read the sample data below, and create a SAS data set called SCORES. Name the 10 scores SCORE1 to SCORE10.
        Sample data for Problem 1–8

123–45–6789 100 98 96 95 92 88 95 98100 90
344–56–7234  69 79 82 65 88 78 78 92 66 77
898–23–1234  80 80 82 86 92 78 88 84 85 83

1-9.You have collected four systolic and four diastolic blood pressure readings (the higher and lower numbers in a reading such as 120/80, respectively) over a period of four months. They are recorded as follows:
Variable     Start-End
Name         Column

----------------------
  SBP1         1–3
  DBP1         4–6
  SBP2         7–9
  DBP2        10–12
  SBP3        13–15
  DBP3        16–18
  SBP4        19–21
  DBP4        22–24

Write a program that uses absolute and relative pointers to read the sample data below. Create a SAS data set called PRESSURE.

Hint: Read all the SBP’s first, then go back and read the DBP’s.

Sample data for Problem 1–9

120 80122 84128 90130 92
140102138 96136 92128 84
122 80122 80124 82122 78

1-10.You are given a raw data file called MIXED_UP that contains two types of records. If column 12 is a 1, the record layout is:
          File MIXED_UP
(Record Layout Where Column 12 = 1)

    Variable      Start-End
      Name          Column
-----------------------------------
     EMP_ID          1–3
     HEIGHT          4–5
     WEIGHT          6–8

If column 12 is a 2, the record layout is:

          File MIXED_UP
(Record Layout Where Column 12 = 2)

    Variable       Start-End
     Name           Column
------------------------------------
   EMP_ID            1–3
   HEIGHT            5–6
   WEIGHT            8–10

Write a SAS program to create a SAS data set called HTWT. Use column input and do not include the data instream.

Sample data (in file MIXED_UP)

00168155   1
002 70 200 2
00362102   1
004 74 180 2

1-11.Write a program to read in pairs of values from the sample data below, representing make of car and gas mileage. Have the program create a SAS data set called CARS. Notice that there are several pairs of values per line. Note also that the names of some makes of cars are more than eight characters long.
Sample Data

Ford 20 Honda 29 Oldsmobile 20 Cadillac 17
Toyota 24 Chevrolet 17

1-12.You have names and test scores in two files, FILE_ONE and FILE_TWO. NAME is in columns 1-10 and SCORE is in columns 11-13. Write a SAS program to read data from both files and create a SAS data set called SCORES. Some sample data are shown below:
    FILE_ONE
---------------
 CODY      100
 PASS       98
 BAGGETT    96
 JOYNER     45

    FILE_TWO
---------------
 FRANKS     66
 BEANS      68


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint