Skip to content

Instantly share code, notes, and snippets.

View cjdinger's full-sized avatar

Chris Hemedinger cjdinger

View GitHub Profile
@cjdinger
cjdinger / jsonlib_communities.sas
Created December 2, 2016 15:53
Example of using JSON libname engine
/****************************************/
/* Example of using JSON libname engine */
/* for discovery, then with a JSON map */
/* Copyright 2016 SAS Institute */
/* written by Chris Hemedinger */
/* http://blogs.sas.com/sasdummy */
/****************************************/
/* split URL for readability */
%let url1=http://communities.sas.com/kntur85557/restapi/vc/categories/id/bi/topics/recent;
@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 / SasWorkspaceExample.ps1
Last active November 10, 2022 19:19
Example of how to use PowerShell to script the SAS Integration Technologies client. You can connect to a remote SAS Workspace and run a program, retrieve the SAS log and listing.
# Example of how to use PowerShell to script the
# SAS Integration Technologies client
# You can connect to a remote SAS Workspace
# and run a program, retrieve the SAS log and listing
# To use: change this script to reference your SAS Workspace
# node name, port (if different), and user credentials
# create the Integration Technologies objects
$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2
/*
%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 / SasWorkspaceDownloadFile.ps1
Created February 20, 2013 22:05
Example of how to use SAS Workspace APIs to download a file from a remote SAS session. Uses SAS LanguageService and FileService APIs, part of IOM.
# Example of how to use PowerShell to script the
# SAS Integration Technologies client
# You can connect to a remote SAS Workspace
# and run a program, retrieve the SAS log and download a file
# To use: change this script to reference your SAS Workspace
# node name, port (if different), and user credentials
# create the Integration Technologies objects
$objFactory = New-Object -ComObject SASObjectManager.ObjectFactoryMulti2
@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 / 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 / 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;
@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. */