Skip to content

Instantly share code, notes, and snippets.

View cjdinger's full-sized avatar

Chris Hemedinger cjdinger

View GitHub Profile
/*
%SURVEYGENMOD macro copied from https://support.sas.com/resources/papers/proceedings17/0268-2017.pdf
%SURVEYGENMOD Macro: An Alternative to Deal with Complex Survey Design for the GENMOD Procedure
Alan Ricardo da Silva, Universidade de Brasilia, Dep. de Estatística, Brazil
Original PDF was not conducive for copy/paste, so this version attempts to correct
for many end-of-line wrapping problems. Might not have caught them all!
*/
%macro surveygenmod(data=, y=, x=, offset=, weight=,
strata=, cluster=, domain=,fpc=, dist=normal,
link=identity, xzip=, intercept=y, scale=deviance,
@cjdinger
cjdinger / rxnorm-api.sas
Created May 5, 2021 21:37
Using the RxNORM API via PROC HTTP
/* this is viagra, from the example on https://mor.nlm.nih.gov/download/rxnav/RxNormAPIs.html# */
%let rxcui = 213269;
/*
Or try acetaminophen with this code
%let rxcui = 209468;
*/
/* allocate a file for the response */
filename rx temp;
@cjdinger
cjdinger / snackbot_byday.sas
Last active April 15, 2020 00:46
SnackBot API and time series analysis
/*
Described in the blog post:
The Internet of Snacks: SnackBot data and what it reveals about SAS life
https://blogs.sas.com/content/sasdummy/snackbot-api-timeseries/
by Chris Hemedinger
*/
/* Use these ODS statements in SAS for Windows or SAS Enterprise Guide */
ods _all_ close;
filename results "%sysfunc(getoption(WORK))/snackbot.htm";
ods html5 file=results style=Htmlencore gtitle options(svg_mode="inline");
@cjdinger
cjdinger / rngs-thanos.sas
Last active May 8, 2018 13:37
Which random number generator did Thanos use?
/* Which RNG did Thanos use? */
/* https://blogs.sas.com/content/sasdummy/rng-avengers-thanos/ */
/* Using STREAMINIT with the new RNG algorithm argument */
%let algorithm = PCG;
data characters;
call streaminit("&algorithm.",2018);
infile datalines dsd;
retain x 0 y 1;
length Name $ 60 spared 8 x 8 y 8;
@cjdinger
cjdinger / SASGlobalForumDemo.ipynb
Last active January 8, 2018 12:50
A sample notebook from SAS Global Forum 2016
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cjdinger
cjdinger / zipfiles_list_details.sas
Last active May 13, 2021 18:47
SAS macros that use FILENAME ZIP and FINFO to list the contents of ZIP files and all of the file details (size, compressed size, full path, etc). See full explanation at http://blogs.sas.com/content/sasdummy/filename-zip-details/
/* Produce a list of ZIP files and their entries from a single folder */
%macro listzipcontents (
targdir= /* a system folder that contains ZIP files */,
outlist= /* output data set for list of files and members */);
filename targdir "&targdir";
/* Gather all ZIP files in a given folder */
/* Searches just one folder, not subfolders */
/* for a fancier example see */
/* http://support.sas.com/kb/45/805.html (Full Code tab) */
@cjdinger
cjdinger / zipfiles_list_extract.sas
Created June 9, 2017 13:58
Example of using FILENAME ZIP to list and extract files from ZIP archives
%macro listzipcontents (targdir=, outlist=);
filename targdir "&targdir";
/* Gather all ZIP files in a given folder */
/* Searches just one folder, not subfolders */
/* for a fancier example see */
/* http://support.sas.com/kb/45/805.html (Full Code tab) */
data _zipfiles;
length fid 8;
fid=dopen('targdir');
@cjdinger
cjdinger / import_renameV7.sas
Last active August 16, 2023 10:42
Example to read CSV file from the web, import to SAS with nonstandard var names, then rename/relabel to conform with standard SAS variable name rules .
/* Example to read CSV file from the web */
/* Import to SAS with nonstandard var names */
/* Then rename/relabel to conform with standard */
/* SAS variable name rules */
/* Fetch the file from the web site */
filename probly temp;
proc http
url="https://raw.githubusercontent.com/zonination/perceptions/master/probly.csv"
method="GET"
@cjdinger
cjdinger / googleanalytics_example.sas
Last active April 13, 2020 09:24
Template SAS program to fetch data from Google Analytics. Requires that you set up your own account and API project in Google developer console. Uses PROC HTTP and JSON libname engine. See blog post here: http://blogs.sas.com/content/sasdummy/using-sas-to-access-google-analytics-apis/.
/* Copyright 2017 SAS Institute */
/* Author: Chris Hemedinger */
/* http://blogs.sas.com/content/sasdummy/using-sas-to-access-google-analytics-apis/ */
/* PREREQUISITES */
/* Use the Google Developer console to define a project */
/* and application, and generate a client-id and client-secret token */
/* Of course, you'll need access to a Google Analytics account with at */
/* least one view profile that allows access to metrics and dimensions. */
/* STEP 1. Need to perform just once in a BROWSER. */
@cjdinger
cjdinger / github_acctstats.sas
Created January 4, 2017 21:40
Using SAS to report on GitHub repos for an organization or user account
/* Fetch the repositories and stats from an */
/* organization's account on GitHub */
/* Requires SAS 9.4 Maint 4 */
/* by Chris Hemedinger */
/* Copyright 2017 SAS Institute Inc. */
/* Change this value to the account you want to report on */
/* Some fun accounts: netflix, spotify, apache */
%let account=sassoftware;
%let acct_type=orgs;