Skip to content

Instantly share code, notes, and snippets.

@statgeek
statgeek / SAS_ODSTITLE
Last active August 29, 2015 13:57
SAS - ODSTITLE - Titles in ODS Graphs
/*This example demonstrates the ODSTitle feature that allows you to
customize a title for an ODS Graphic, SAS 9.3+*/
data Trans;
input Thick @@;
label Thick = 'Plating Thickness (mils)';
datalines;
3.468 3.428 3.509 3.516 3.461 3.492 3.478 3.556 3.482 3.512
3.490 3.467 3.498 3.519 3.504 3.469 3.497 3.495 3.518 3.523
3.458 3.478 3.443 3.500 3.449 3.525 3.461 3.489 3.514 3.470
@statgeek
statgeek / SAS_7zip.sas
Last active April 4, 2023 17:37
SAS - Zip Files using 7Zip
options noxwait noxsync;
data _null_;
*Path to winzip program;
zipexe='"C:\Program Files\7-Zip\7z.exe" a -tzip';
*Zip file name;
zipfile="C:\My Documents\Sample.zip";
*File to be zipped;
file="C:\Temp\Sample.txt";
*Full cmd line to be passed to command line. It embeds the quotes for paths with spaces;
@statgeek
statgeek / SAS_variableList
Created March 17, 2014 16:04
SAS - Variable List in Results WIndow
/*This code will print all the variables into the output window,
space delimited, replace the data= with the dataset of interest.*/
proc contents data=sashelp.class short;
run;
@statgeek
statgeek / SAS_fiscalYear
Created March 17, 2014 16:05
SAS - Fiscal Year start and end from a date value
/*How to calculate the fiscal year start and end from a date value*/
%let date="01Sep2013"d;
data _null_ ;
fstart=intnx('year.4',&date,0,'b') ;
fend=intnx('year.4',&date,1,'b')-1;
@statgeek
statgeek / SAS_stylesRTF
Created March 17, 2014 16:45
SAS - RTF Style for tables
/*This program is a template for a tight table style for Word Documents,
RTF.
Originally written by Ryan Woods, BC Cancer Agency*/
proc template;
define style styles.newrtf;
parent=styles.rtf;
style header / background = white font=(Times, 11pt, Bold);
replace fonts /
'TitleFont2' = ("Times",12pt,Bold Italic)
@statgeek
statgeek / SAS_macroLoopVars
Created March 17, 2014 16:49
SAS - Macro Loop Through Variable Lists
/*This Loops thoough a set of variables where the variables
are separated by "|". Any other delimiter can be used
and specified in the scan function as well*/
%macro loop(varlist);
%let i=1;
%do %while (%scan(&varlist, &i, |) ^=%str());
%let var=%scan(&varlist, &i, |);
%put &var;
@statgeek
statgeek / SAS_dateDimension.sas
Last active March 3, 2020 19:42
SAS - Date Dimension
/*This creates a date dimension table that can be used for
looking up dates. This is less relevant as SAS has allowed
for custom intervals, but a quick solution often.*/
%MACRO DATE_DIMENSION(startdate=, enddate=, outfil=);
data &outfil;
retain number_workdays;
do _n_ = &startdate to &enddate;
@statgeek
statgeek / SAS_stdRates.sas
Last active August 16, 2023 10:40
SAS - Standardized Rates
/*This program illustrates how to age standardize rates using the age data for Canada 1991*/
*Source Data:http://www.apheo.ca/resources/indicators/Standardization%20report_NamBains_FINALMarch16.pdf
*Source Code:http://support.sas.com/documentation/cdl/en/statug/65328/HTML/default/viewer.htm#statug_stdrate_syntax01.htm
;
*Create dataset with Canada Standard Rates for 1991;
data CanadaSTDRATE;
format AgeGroup 2. AgeGroupDesc $5. Canada1991 comma12.;
informat Canada1991 comma12.;
@statgeek
statgeek / SAS_listExcelSheets
Created April 9, 2014 21:55
List all Excel sheets in a workbook
*This code will create a libname reference to an Excel file and list all Sheets in the results window;
libname sample pcfiles path='C:\Temp\Sample_v2.xlsx'; *your statement will depend on your OS/Excel version;
proc contents data=sample._all_;
run;
rsubmit wait=no macvar=check_test;
proc freq data=table.large_table;
table variable_levels/out=check;
run;
endrsubmit;