In SAS, the INFILE statement is used to read data from an external file into a SAS data set. The INFILE statement supports a number of options that can be used to customize the way in which the data is read. Some of the commonly used INFILE options are:
1. FILENAME: specifies the name of the external file to be read.
2. DLM: specifies the delimiter used to separate fields in the input file.
3. DSD: specifies that the data values in the file are separated by delimiters and that the values may contain delimiter characters, so they need to be interpreted as character strings.
4. LRECL: specifies the record length for the input file.
5. MISSOVER: specifies that if a missing value is encountered in the input data, SAS should continue processing the remaining data.
6. FIRSTOBS: specifies the first observation number to be read from the input file.
7. OBS: specifies the last observation number to be read from the input file.
data mydata;
infile ‘datafile.txt’ DLM=’,’ DSD MISSOVER FIRSTOBS=2 OBS=10;
input var1 $ var2 var3;
run;
In this example, the INFILE statement specifies the external file to be read using the FILENAME option. The DLM option specifies that the delimiter used to separate fields in the input file is a comma. The DSD option specifies that the data values in the file are separated by delimiters and that the values may contain delimiter characters. The MISSOVER option specifies that if a missing value is encountered in the input data, SAS should continue processing the remaining data. The FIRSTOBS option specifies that the first observation to be read from the input file is 2, and the OBS option specifies that the last observation to be read from the input file is 10.
By using these options, SAS can read data from external files more accurately and efficiently, and provide users with more flexibility in how they process and analyze data.
What is truncover?
In SAS, the TRUNCOVER option is used in the INFILE statement to control the way in which SAS handles missing values in the input data.
When the TRUNCOVER option is used, SAS reads a record from the input file as long as it contains enough data to satisfy the INPUT statement. If the record ends before all the variables are read, SAS sets the remaining variables to missing values.
For example, consider the following input data:
John,25,150
Jane,32
Tom,40,200
data mydata;
infile ‘datafile.txt’ delimiter=’,’ truncover;
input name $ age weight;
run;
The TRUNCOVER option allows SAS to read the second record, which has a missing value for the “weight” variable, and set the “weight” variable to a missing value.
Without the TRUNCOVER option, SAS would read the second record as the beginning of the next record, and would not be able to read the “age” value for Jane, causing an error.
While the TRUNCOVER option can be useful in situations where missing values are expected in the input data, it can also lead to unexpected results if used improperly. It is important to ensure that the TRUNCOVER option is used in combination with other options, such as the MISSOVER option, to handle missing data appropriately.
What is scanover?
In SAS, SCANOVER is an option in the INPUT statement that controls how SAS reads delimited input data.
When the SCANOVER option is used, SAS scans the input data for delimiter characters and uses them to separate the data into individual fields. If a field is empty or missing, SAS skips it and moves on to the next field.
For example, consider the following input data:
John 25 150
Jane 32 130
Tom 40 200
If we use the following SAS program to read this data:
data mydata;
infile ‘datafile.txt’ dlm=’ ‘ scanover;
input name $ age weight;
run;
The SCANOVER option allows SAS to read the input data even though there are no commas or other delimiters between the fields. In this case, the SPACE character is used as the delimiter. SAS reads the first field as the “name” variable, the second field as the “age” variable, and the third field as the “weight” variable.
While the SCANOVER option can be useful in situations where there are no consistent delimiters in the input data, it can also lead to unexpected results if used improperly. It is important to ensure that the SCANOVER option is used in combination with other options, such as the MISSOVER option, to handle missing data appropriately.