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
@FriedEgg
FriedEgg / aes.sas
Created June 9, 2020 16:05
AES Encrpytion and Decryption functions for SAS using PROC GROOVY and Data Step Java Component Object
filename cp temp;
proc groovy classpath=cp;
submit parseonly;
import javax.crypto.spec.SecretKeySpec
import javax.crypto.spec.IvParameterSpec
import javax.crypto.Cipher
class GroovyCrypter {
def expandKey (def secret) {
@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";
@FriedEgg
FriedEgg / SASHash.sas
Last active July 11, 2022 05:28
Using PROC GROOVY in SAS to Calculate Hash Digests
filename inc temp;
data _null_;
file inc;
input @;
put _infile_;
cards4;
filename cp temp;
proc groovy classpath=cp;
add sasjar="commons_codec" version="1.7.0.0_SAS_20121211183158"; *version is specific to SAS Installation and may differ from this;
@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;
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;
from win32com.client.dynamic import Dispatch
factory = Dispatch("SASObjectManager.ObjectFactoryMulti2")
serverDef = Dispatch("SASObjectManager.ServerDef") # no extra properties... local/zero-config server
sas = factory.CreateObjectByServer("SASApp", True, serverDef, "", "")
code = """
*pre-code;
@FriedEgg
FriedEgg / workspace_server_reconnect_property.sas
Created March 13, 2018 21:09
Using PROC METADATA in SAS to query SAS Workspace Server Properties
/* configure connection to metadata server */
options metaserver="hostname" metaport=8561;
/* here we are defining out metadata query */
/* we are making a call to GetMetadataObjects
and requesting a response listing all SAS
Workspace Servers defined in metadata
along with the associated properties which
contain the work reconnect in their
property name. */
@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 / jalali_fcmp.sas
Created February 16, 2015 14:27
Methods for dealing with Non Gregorian Calendars in SAS
proc fcmp;
function to_jalali(sasdate) $ 200;
y=year(sasdate)-1600;
m=month(sasdate)-1;
d=day(sasdate)-1;
@FriedEgg
FriedEgg / heart.sas
Last active August 29, 2015 14:15
A Geeky Valentines
/* inspired by Rick Wicklin -- http://blogs.sas.com/content/iml/2015/02/11/binary-heart/ */
proc fcmp outlib=work.funcs.graph;
function heartx(t);
return(16*sin(t)**3);
endsub;
function hearty(t);
return(13*cos(t) - 5*cos(2*t) - 2*cos(3*t) - cos(4*t));
endsub;