Reading and Verifying Data

Verifying the Code That Reads the Data

Before you read a complete external file, you can verify the code that reads the data by limiting the number of observations that SAS reads. You can use the OPTIONS statement with the OBS= option before the IMPORT procedure to limit the number of observations that SAS reads from your external file.
The program below reads the first five records in the external data file that is referenced by PROC IMPORT.
options obs=5;
proc import datafile="C:UsersStudent1certoot.csv"
  dbms=csv
  out=shoes
  replace;
  getnames=no;
run;

Checking DATA Step Processing

After PROC IMPORT runs the DATA step to read the data, messages in the log verify that the data was read correctly. The notes in the log indicate the following:
  • Five records were read from the infile ‘C:UsersStudent1certoot.csv
  • The SAS data set work.shoes was created with five observations and seven variables.
Log 4.2 SAS Log
NOTE: The infile 'C:UsersStudent1certoot.csv' is:
      Filename=C:UsersStudent1certoot.csv,
      RECFM=V,LRECL=32767,File Size (bytes)=657,
      Last Modified=25Jun2018:13:37:49,
      Create Time=25Jun2018:13:37:49

NOTE: 5 records were read from the infile
      'C:UsersStudent1certoot.csv'.
      The minimum record length was 51.
      The maximum record length was 81.
NOTE: The data set WORK.SHOES has 5 observations and 7
      variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


5 rows created in WORK.SHOES from
C:UsersStudent1certoot.csv.



NOTE: WORK.SHOES data set was successfully created.
NOTE: The data set WORK.SHOES has 5 observations and 7
      variables.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.05 seconds
      cpu time            0.04 seconds

Printing the Data Set

The messages in the log seem to indicate that the PROC IMPORT step correctly accessed the external data file. But it is a good idea to look at the five observations in the new data set before reading the entire external data file. The system option OBS=5 is still in effect, so you do not have to specify it again. You can submit a PROC PRINT step to view the data.
Data sets are assigned to the default Work library when the library reference is omitted. The example stored the Shoes data set in the temporary library, Work.
The following PROC PRINT step prints the Work.Shoes data set.
proc print data=work.shoes;
run;
The PROC PRINT output indicates that the variables in the Work.Shoes data set were read correctly for the first five records.
Figure 4.2 PROC Print Output
PROC Print Output

Reading the Entire External File

To modify the PROC step to read the entire external file, restore the default value to the OBS= system option. To do this, set OBS=MAX and then resubmit the program.
options obs=max;
proc import datafile="C:UsersStudent1certoot.csv"
  dbms=csv
  out=shoes
  replace;
  getnames=no; 
run;
Note: SAS Studio sets OBS=MAX before each code submission.
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.21.47