My SAS Programming Tips
- Displaying the contents of the Program Data Vector:
put (_all_)(=/);
- How I deal with temporary variables: useful naming convention, and drop with a wildcard.
- Parsing character fields: use of
scan and input functions.
IF vs. WHERE - Yes, it matters: their effects on _N_ .
- Forcing printed output in the event of an empty data file: when it is better to see headers and an empty report than to see nothing at all.
- A SAS macro to parse a path into its folder, filename, and extension: and how to read a SAS file given its full path.
- Parsing drug dosages: a use case for the
anyalpha and substr functions: another data wrangling tip.
- Using
PROC FORMAT in data munging: it's not just for reporting.
- More on
PROC FORMAT : writing formats to specific libraries; copying formats from one library to another.
- Three SAS Enterprise Guide Options
- Simple dedupe of SAS table based on all columns: using
NODUPKEY and BY _ALL_
- Writing text files to the SAS work library: how and why.
- Error message "Insufficient authorization to access C:\WINDOWS\system32\sasgraph.png": How to resolve.
- Scoring regression models:
PROC SCORE : OUTEST option and PROC SCORE .
- Scoring regression models: The "Missing Y" method.
- Zero observations imported for .xls file? It opens in Excel but SAS can't read it? How to resolve.
- Dates off by ten years? Dealing with Unix/Posix dates.
- Is this foreign key valid? (1 of 3) Using
PROC FORMAT for data validation.
- Is this foreign key valid? (2 of 3) Using the
MERGE statement and the IN= option.
- Is this foreign key valid? (3 of 3) Using a hash table.
- A comprehensive example of using hash tables Not one but two hash tables.
- Format blank when zero Also
CASE and COALESCE .
- Delete rows using
PROC SQL . Beware of this gotcha! (Logical vs. physical delete.)
- Delete rows using
MERGE statement in a DATA STEP . Also BY statement and IN= option.
- Looping with
do over : looping over (through) an array.
OPTION VARINITCHK : show error message (rather than a note) when variables are not initialized.
- Selecting a datetime value into a macro variable, and using that macro variable in a subsequent
IF or WHERE statement.
- Writing SAS reports to MS Word using
ODS RTF FILE and ODS RTF CLOSE .
- Using
SQLOBS when creating macro variables within PROC SQL .
- A simple way to left justify macro variables. (It makes titles look nicer.)
- Using
IN in a macro IF . (It requires OPTIONS MINOPERATOR .)
- Two ways to create an empty SAS dataset:
DATA STEP with DELETE and STOP , or PROC SQL with LIKE .
- A macro to drop a variable from a SAS dataset if that variable exists. My macro
DROP_VAR_IF_EXISTS .
- Encoding passwords with
PROC PWENCODE .
- Using SAS to FTP an external file. My macro
FTPFILE , because the FTP access engine was corrupting my files.
%INCLUDE a file if it exists.. (Conditionally include a %INCLUDE file.)
- Cross tabulations (crosstabs) using
PROC FREQ ). Also ODS NOPROCTITLE , and PROC FREQ options NOCOL , NOROW , and NOPCT .
- Using
PROC FREQ to conduct a chi-square test of independence. Includes CHISQ option.
- Using
PROC FREQ to conduct a goodness of fit test. Includes CHISQ and TESTP options.
- Using
PROC TTEST to conduct a test of hypothesis about a population mean. Includes ALPHA and SIDE options, and how to find the confidence interval of a population mean.
- Using
PROC FREQ to conduct a test of hypothesis about a population proportion . Also how to find the confidence interval of a population proportion.
- K-means clustering in one dimension using
PROC FASTCLUS .
- Forcing a variable of unknown type to numeric or character. A hack with the
cat function.
|