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) {
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 / 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 / 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 / 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;
@FriedEgg
FriedEgg / SasAdoDBExample.ps1
Last active August 29, 2015 14:15
Examples for using ADO Db with SAS to create librefs and read from sas7bdat files with SQL from remote servers
$conn = New-Object -ComObject ADODB.Connection
#Connect to a remote server using IOM
$conn.Open('Provider=sas.IOMProvider.9.3;User ID=user;Password=pass;Data Source="";SAS Machine DNS Name=workspace.mycompany.com;SAS Port=8591;SAS Protocol=2')
#Assign a new libref using ADODB
$cmd = New-Object -ComObject ADODB.Command
$cmd.ActiveConnection = $conn
$cmd.CommandType = adCmdText
$cmd.CommandText = 'libname foo "/path/to/something"'
$conn = New-Object -ComObject ADODB.Connection
#Connect to a remote server using IOM
$conn.Open('Provider=sas.IOMProvider.9.3;User ID=user;Password=pass;Data Source="";SAS Machine DNS Name=workspace.mycompany.com;SAS Port=8591;SAS Protocol=2')
#Assign a new libref using ADODB
$cmd = New-Object -ComObject ADODB.Command
$cmd.ActiveConnection = $conn
$cmd.CommandType = adCmdText
$cmd.CommandText = 'libname foo "/path/to/something"'
/*
This SAS program uses the ARRPI translator at:
http://isithackday.com/arrpi.php
To translate whatever English text you supply into
Pirate speak for Talk Like a Pirate Day
This is a modification of the posting by Chris Hemedinger
to use PROC DS2 and the HTTP Package in place of PROC HTTP
*/
@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";