Skip to content

Instantly share code, notes, and snippets.

View FriedEgg's full-sized avatar

Matthew Kastin FriedEgg

  • SAS Institute Inc.
  • Hershey, Pennsylvania
View GitHub Profile
import com.sas.iom.SASIOMDefs.GenericError;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ZeroConfigWorkspaceServer;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryException;
import com.sas.services.connection.SecurityPackageCredential;
import com.sas.iom.SAS.ILanguageService;
@FriedEgg
FriedEgg / SASWorkspaceUploadFile.py
Created February 19, 2014 05:02
Example of how to use SAS Workspace APIs to upload a file to a remote SAS session. Uses SAS LanguageService, FileService and BinarySteam APIs, part of IOM.
# Example of how to use Python on Windows to
# transfer a file to a SAS Integration Technologies client
# You can connect to a remote SAS Workspace
# and write a file through a binary stream
# run a program and collect the SAS log
__author__ = 'FriedEgg'
import win32com.client,os,binascii
@FriedEgg
FriedEgg / twitter4sas.sas
Last active September 20, 2021 03:08
Twitter Search API for SAS using PROC GROOVY
/*-----------------------------------------------------------------------------------------------------------------------------------------
*-Usage Parameters
*/
%let api_key = <YOUR TWITTER API_KEY>;
%let api_secret = <YOUR TWITTER API_SECRET>;
%let search_query = %23SASGF13+OR+%23SASGF14+OR+%23SASGF15;
@FriedEgg
FriedEgg / twittersteam.sas
Created August 16, 2014 08:13
Twitter Streaming API for SAS using PROC GROOVY
filename cp temp;
filename ivy "%sysfunc(pathname(work,l))/ivy.jar";
proc http
method = 'get'
url = 'http://central.maven.org/maven2/org/apache/ivy/ivy/2.3.0-rc1/ivy-2.3.0-rc1.jar'
out = ivy
;
run;
@FriedEgg
FriedEgg / GoogleMapsGeocode.sas
Created August 27, 2014 04:18
An interface for using Google Geocode API with PROC GROOVY in SAS
%let api_key=<<YOUR GOOGLE API_KEY>>;
filename cp temp;
filename ivy "%sysfunc(pathname(work,l))/ivy.jar";
proc http
method = 'get'
url = 'http://central.maven.org/maven2/org/apache/ivy/ivy/2.3.0-rc1/ivy-2.3.0-rc1.jar'
out = ivy
@FriedEgg
FriedEgg / GeocodeFCMP.sas
Created August 27, 2014 06:13
Another implementation of using Google geocoding API in SAS, this time using PROC FCMP
proc fcmp outlib=work.func.api;
subroutine geocode(address $, adr $, lat, lng);
outargs adr, lat, lng;
api_key="<<YOUR API KEY>>";
length url c adr $ 32767 prxadr prxlat prxlng lat lng 8 fileref $ 8;
@FriedEgg
FriedEgg / GoogleTrends4SAS.sas
Last active August 29, 2015 14:07
An interface for collecting search results from the unofficial Google Trends API using PROC GROOVY in SAS
/** GoogleTrends4SAS
*
* Description: An interface for collecting search results from the unofficial Google Trends API using PROC GROOVY
*
* Note: YOU MUST ALTER THE GROOVY CODE MANUALLY.
* Find the value of PREF cookie on the machine executing the code and enter it below.
* Note: As writted here for SAS 9.4 on Linux x64, available versions of Groovy for sasjar will be dependent on version and OS
*/
filename cp temp;
@FriedEgg
FriedEgg / textWidth.sas
Created October 30, 2014 16:36
Calculate the width of the string using PROC GROOVY in SAS for a given message, font and font size
/*a manual implementation*/
proc groovy;
submit;
import java.awt.Font;
import java.awt.Canvas;
font = new Font("Arial", Font.PLAIN, 12)
c = new Canvas()
metrics = c.getFontMetrics(font)
@FriedEgg
FriedEgg / fileChooser.sas
Created December 17, 2014 18:16
Use PROC GROOVY and the JFileChooser to create a window prompt for selecting a file or directory in SAS
proc groovy;
submit;
import javax.swing.JFileChooser
def openChooser = new JFileChooser(
dialogTitle: "Choose a file or directory",
fileSelectionMode: JFileChooser.FILES_AND_DIRECTORIES
)
fc = openChooser
fc.showOpenDialog()
exports = [selectedFile: fc.selectedFile]
@FriedEgg
FriedEgg / BingTranslate.sas
Created December 25, 2014 17:33
Utilize the Bing/Microsoft Translator API for Multi-Language Translating of text in SAS using PROC GROOVY
/*Sign up for the Bing Translator, 2million characters/month of free translating!*/
%let client_id=<<Your Client ID>>;
%let client_secret=<<Your Client Secret>>;
%let text=Merry Christmas;
%let from=en; /*English*/
%let to=es; /*Spanish*/
/*Link to language codes: http://msdn.microsoft.com/en-us/library/hh456380.aspx*/
filename ivy "%sysfunc(pathname(work,l))/ivy.jar";