Fundamentals Flashcards
(114 cards)
What are the three functions of a data statement in a DATA step?
- Signals the beginning of a data step
- Defines where to store SAS dataset
- Names the dataset
What is the function of the Infile statement in a DATA step?
The infile statement declares the text file to import.
What is the function of the input statement in a DATA step?
Input statement defines the name, type (character or numeric) and length of each column being generated from the raw data.
What is the function of a run statement in a DATA step?
The run statement completes the DATA step and executes the code once it’s submitted.
Give an example of a list input sequence in a DATA step.
Data sasdatasetname;
infile ‘textfilename’;
input column1 column2 column3…etc;
run;
Explain List input in a DATA
- A method of reading data values from an input data file where values are delimited by spaces, tabs, commas or other specified character.
- Variables are specified in the INPUT statement and read in the specified order.
-With List Input, the INPUT statement scans along the raw data record line, when a space is found, it assumes the end of the field has been reached.
Name some limitations of list input
- Blanks must separate the fields
- The values for character columns are restricted in that: Default length is eight characters
- No embedded blanks are allowed with the default. For example, data containing ‘Dave Derry’ as a name will take ‘Dave’ as 1 column and ‘Derry’ as another.
- Mismatched columns if there’s missing data
Briefly describe column input
Requires the column location of the variable values to be known and specified in the input statement.
Briefly describe column input
Requires the column location of the variable values to be known and specified in the input statement.
Describe formatted input
- This style of INPUT statement allows values to be read using an informat (a template used by SAS to read values)
- Requires that the column location at which to start
reading the value and the name of the informat to use are specified
Write the syntax for formatted input
@Value_Start_Position var_name informat_name
What is the purpose of using a DATA step cut and paste method?
This method has two purposes;
1. Cut and paste data from another program
2. Type the date into the SAS program
How is the DATA step cut and paste method used?
- Uses datalines/cards statement instead of infile statement (in a different place)
-The data is pasted or typed into the editor making it unsuitable for large amounts of data - This technique can be used with any list, column or formatted input methods.
What is delimiter-sensitive data (DSD)?
DSD are files that do not come separated by blank spaces, instead, they use another character in between values.
Arrange the
following SAS keywords in the correct order for reading an external file.
INPUT
RUN
INFILE
DATA
Match the SAS keywords with the correct definition:
a) Specifies the name of the text file that the program is to read;
b) Completes the DATA step processing;
c) Starts the DATA step processing and names the output table;
d) Defines the variable names and types.
- DATA: Starts the DATA step processing and names the output table
- INFILE: Specifies the name of the text file that the program needs to read
- INPUT: Defines the variable names and type
- RUN: Completes the DATA step processing
Briefly explain the Import procedure
- Proc import converts external data such as space, tab,comma delimited files, and database files (e.g excel spreadsheets) into SAS data sets
- Provides a simple syntax whilst writing and running the DATA step code in the background
What is the basic syntax for a proc import procedure?
Proc import datafile=”filename/fileref
out=sas-table-name
<DBMS=Identifier>
<Replace>;
run;
</Replace>
What is the basic syntax for a proc export procedure?
Proc import data=sas-table-name
outfile= “filename”/fileref
<DBMS=Identifier>
<Replace>;
run;
</Replace>
How many variables does a SAS program have?
2.
a. Character (Must be enclosed in quotation marks)
b. Numeric
What are numeric expressions?
- Mathematical expressions can be constructed in the SAS language various signs such e.g A=c+d, - * / etc
- Expressions within parentheses are evaluated prior to expressions outside of parentheses.
What are numeric expressions?
- Mathematical expressions can be constructed in the SAS language various signs such e.g A=c+d, - * / etc
- Expressions
within parentheses are evaluated prior to expressions outside of parentheses.
describe The LENGTH statement.
- The LENGTH statement allows the programmer to control how the new variable will be
created - As a general rule, LENGTH statements should always be placed at the beginning of the DATA step
In which case would you use a Set statement over infile and input statements?
The DATA step is used to manipulate data. The source data can either be external ‘Non SAS’, or an existing SAS table
-If the source file used is external, Infile and Input statements are used
- If the source data is an existing SAS table then a SET statement is used instead:
What is a Set statement?
- Through implied DATA step looping, a SET statement reads all observations in a SAS data set unless options are used to dictate otherwise.
- By default, all variables are read and their properties are as defined in the source data set.
- The SET statement reads a observation or row from a SAS table each time it is executed