Reading Long Records from an External File - SAS Programming

When reading in external raw data files,you can, for the most part, rely on default values for describing architectural features of the files.You can override defaults when necessary,to describe such features as the record format,block size,or logical record length of the file.These features are described by the INFILE statement options RECFM=, BLKSIZE=,and LRECL= respectively.

We only concern ourselves here with the last one,LRECL=.(By the way, this option is named after that famous Spanish bullfighter,"El Rec-el.")You use this option to indicate the maximum record length of the input file and only need it when the record length exceeds your system dependent default.Suppose you have a file,LONGFILE,with 256-byte records and a system default logical record length of 80.You can account for the long record length by coding the INFILE statement as follows:

INFILE 'LONGFILE' LRECL=256;

You can also use the LRECL= option when you want to read only part of very long records. You may code an LRECL= value larger or smaller than the actual record length in your input file and it will work just fine.

Problems

  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
  2. Al 68 130 80
    B3 101 148 86
    C2 . . 72
    Dl 72 140 88
  3. . Redo problem 1-1 to read the comma-delimited raw data file VITALC shown below: external file VITALC
  4. Al, 68, 130, 80
    B3, 101, 148, 86
    C2, ., ., 72
    Dl, 72, 140 , 88
  5. 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.
  6. Sample data for Problem 1-3
    Stevenson Ph.D. Y 2
    Smith Ph.D. N 3
    Goldstein M.D. Y 1
  7. 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:
  8. Sample data for Problem 1-4
    George Stevenson Ph.D. Y 2
    Fred Smith Ph.D. N 3
    Alissa Goldstein M.D. Y 1
  9. 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.
  10. Reading Long Records from an External File

  11. 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
  12. Reading Long Records from an External File

  13. 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.
  14. Reading Long Records from an External File

    Hint: Use the DOLLAR7, informal to read PRICE.
  15. 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 inform al 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.
  16. Reading Long Records from an External File

  17. 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.
  18. They are recorded as follows:

    Reading Long Records from an External File

    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 DBF's.sample data for problem 1-9
  19. 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:
  20. File mixed up

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

    File mixed up

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

    File mixed up

  21. 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.
  22. 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:
  23. Some sample data


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics