SAS Flashcards
(41 cards)
what do we call statements that begin/end a step?
step boundaries e.g. run;
what are global statements?
impact the entire SAS session and set options/values that will remain in effect until they are changed or the session ends e.g. title, options, libname, footnote
how can you comment?
- in front of the line to comment one line
/* comment */ for any length of text
what are the 3 required attributes of a structured SAS column?
name (1-32ch, must start with letter/underscore), length (default numeric=8bytes/16digits, default char=length of column name, can be up to 32767bytes), type (char/numeric)
how do you create/use a macrovariable?
use %LET statement to define macrovariable. WIthin code can then use & to refer to it.
e.g. %LET path = xyz
…&path
SAS will automatically replace path with xyz
macrovariables must have double quotations
when defining a library, what is the method?
LIBNAME libname DATATYPE path libname must be <=8 characters.
Which procedure produces a report about the descriptor portion of a table?
PROC CONTENTS
what are rows and columns also called?
observations and variables
Which statement can be used to subset the rows read in a PROC step?
WHERE
Which procedure lists the distinct values for one or more columns?
PROC FREQ
If you want to format just numeric or character types of columns, what keyword would you use?
format NUMERIC fmt;
format CHARACTER fmt;
for all columns use ALL
describe the PROC MEANS step
generates simple summary statistics for each numeric column in input data by default unless VAR statement used
in the PROC MEANS step, what does CLASS, WAYS, OUTPUT and OUT do?
CLASS - specifies columns to group by before calculating statistics
WAYS - specifies the number of ways to make unique combinations of class variables
OUTPUT - provides the option to create an output table with specific output statistics
OUT= - names output table to be created
describe the PROC FREQ step
creates a frequency table for each variable in the input table by default. Can specify variables to be analysed using TABLES statement
how do you import structured/unstructured data?
structured e.g. xlsx use LIBNAME or PROC IMPORT
unstructured e.g. CSV use PROC IMPORT
in the PROC SORT step, what does NODUPKEY, DUPOUT do?
NODUPKEY keeps the first row for each unique value of the columns listed in the by statement
DUPOUT creates an output table containing duplicates
In general, what are the 2 phases of the DATA step?
COMPILATION: creates PDV, establishes data attributed and rules for execution
EXECUTION: reads, manipulates and writes data
what are the 2 default variables created in the DATA step?
N counts number of iterations through the data step when processing
ERROR initialised at 0 and goes up by 1 when any error detected in each iteration
when to use DROP/KEEP vs DROP=/KEEP=?
DROP/KEEP added within the data step
DROP=/KEEP= added to a table on the DATA statement or SET statement
- when dropped/kept on SET statement, column is unavailable for processing in the DATA step
DO UNTIL vs DO WHILE
DO UNTIL: condition checked at bottom of DO loop => always executes at least once
DO WHILE: condition checked at the top of DO loop => doesn’t iterate at all if condition is initially false
describe the MERGE statement
all tables in the MERGE statement must be sorted by the column listed in the BY statement. it then combines tables where the BY columns match. Can use in= to subset using IF statement.
what function do you use to convert
a) numeric to character
b) character to numeric
a) PUT(numeric-var, format)
b) INPUT(char-var, informat)
how can you create a SAS date value?
MDY(month, day, year) function
TODAY() returns current date
how can you increase a date by certain interval e.g. to last day of the following month
INTNX(interval, start-from, increment, alignment)
e.g. INTNX(‘month’, DATE-col, 1, ‘end’);