Making a Report Flashcards
Notation and facts about:
- Block comment (and 3 facts about them)
- Comment statement
Block comments: /* comment */
- Can be any length and contain semicolons.
- Cannot be nested.
- Avoid placing in first or second columns because SAS might interpret them as signal to end job or session
Comment statement: * comment statement ;
- They can begin in columns 1 and 2
- Cannot contain internal semicolons
4 common syntax errors
invalid options, missing semicolons, unmatched quotation marks, and misspelled keywords
Is a user-created library automatically available in a SAS session?
NO, must assign a libref to make it available.
LIBNAME statement
LIBNAME libref ‘filepath’
filepath = physical location of the library
Note: does not need a run statement
rules for naming libref
- 1-8 characters long
- Must begin with letter or underscore
- Remaining characters can be letters, numbers, or underscores
T or F: Macro variables can be referenced in double or single quotation marks
False. Macro variables can only be referenced in double quotation marks
- How do you generate a report of a library’s contents?
- How do you suppress descriptors data of each individual file in the library?
- PROC CONTENTS DATA = libref._ALL_;
RUN;
- PROC CONTENTS DATA = libref._ALL_ nods;
RUN;
nods = no descriptors
(make sure to add space before nods)
How do you distinguish numerical and character variables on a table?
SAS automatically displays numerical variable right-aligned and character variables left-aligned
How to dissociate a library?
LIBNAME libref clear;
How does SAS display missing values for character and numeric variables?
Character: blank
Numeric: . (period)
Change what SAS displays for missing numeric values
MISSING = ‘character’
Length for character and numeric values
Character: 1 - 32,767 bytes
Numeric: 8 bytes (16 or 17 significant digits)
Rules for naming variables
- Can be 1 -32 characters long
- Start with letter or underscore
- Can contain numbers, letters, or underscores
- Can be uppercase or lowercase
- After variable is created, can refer to it in any case in code without affecting way in which it’s stored
How to add totals of several variables within one SUM statement
Separate variable with blank:
SUM var1 var2;
Which statement do you use to choose specific variable to display in a report?
VAR
How to subset observations in a report?
Within PROC PRINT, use WHERE statement
Use where statement to select variables that equal to one in a list
WHERE variable in (‘condition1’, ‘condition2’)
or WHERE variable in (‘condition1’ condition2’)
What happens when you use 2 consecutive WHERE statements?
proc print data=orion.sales;
where Country=’AU’;
where Salary<30000; run;
The second where statement replaces the first one! Intead use logical operators (AND, OR, NOT)
Which operator do you use to include observations with a certain substring in a report? Which statement do you use it with? What is the symbol for it?
CONTAINS. WHERE. ?
WHERE variable CONTAINS ‘substring’;
or
WHERE variable ? ‘substring’;
Note: substring is case-sensitive
Name 5 special operators that can only be used in a WHERE statement
- BETWEEN AND : WHERE Salary between 5000 and 10000
- WHERE SAME AND condition: add to a where expression.
- WHERE variable IS NULL: a missing value
- WHERE variable IS MISSING: a missing value
- WHERE variable LIKE: matches a pattern (use % for any number of characters or _ for one character)
How do you replace the observation number column with another variable?
Use ID variable;
How to sort observations?
Use PROC SORT before printing. Note that by default, SAS replaces the original data set unless you use to create a new dataset.
PROC SORT DATA = SASDataSet
[OUT = NewDataSet];
BY [descending] variable1 [decending] variable2 variable3;
RUN;
(Stuff inside [] is optional)
How to generate reports by groups
Use BY variable; under PROC PRINT
Remember to sort by the variable first
Where it is best to add a WHERE statement? PROC SORT or PROC PRINT
PROC SORT