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_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_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;
@statgeek
statgeek / SAS_ordinal_fmt
Created June 4, 2014 15:17
Create a format for ordinal numbers (1-1st, 2-2nd)
data ordinal_format;
length label $8.;
do number=1 to 300;
numstring = put(number, 16. -l);
if prxmatch('/(?<!1)1\s*$/',numstring) then ending='st';
else if prxmatch('/(?<!1)2\s*$/',numstring) then ending='nd';
else if prxmatch('/(?<!1)3\s*$/',numstring) then ending='rd';
else ending = 'th';
ordstring =catt(numstring, ending);
@statgeek
statgeek / SAS_GTL_Title
Created December 6, 2014 03:50
SAS - Add by value title to GTL Template
*valid in SAS 9.3+, using the dynamic variable _byval_ that is automatically created by SAS;
proc template;
define statgraph scatter;
dynamic _x _y _byval_;
begingraph;
entrytitle "Scatter Plot of " _x " by " _y " for Sex = " _byval_;
layout overlay;
scatterplot x=_x y=_y;
<?php
$conn = new COM("ADODB.Connection");
$conn->Open('Provider=sas.IOMProvider.9.3;User ID=user;Password=pass;Data Source="";SAS Machine DNS Name=my.server.com;SAS Port=8591;SAS Protocol=2');
$cmd = new COM("ADODB.Command");
$cmd->ActiveConnection = $conn;
$cmd->CommandType = 1;
$cmd->CommandText = 'libname foo "/my/path"';
$cmd->Execute();
@statgeek
statgeek / sas_shp_tableau
Created June 19, 2015 16:29
SAS - Import SHP file and create CSV for Tableau
PROC MAPIMPORT OUT=Polygon DATAFILE="Boundaries.shp";
run;
data Polygon;
set Polygon;
by feature_name notsorted;
if first.feature_name then order=0;
else order+1;
run;
@statgeek
statgeek / SAS_call_execute_split_file
Created September 25, 2015 17:37
SAS - split file into subsets using call execute
proc sort data=sashelp.class out=class;
by age;
run;
data _null_;
set class;
by age;
retain count;
if first.age then do;