Skip to content

Instantly share code, notes, and snippets.

*--- setup unit test;
%let source_dir = /user/SASTest/source;
%let target_dir = /user/SASTest/target;
x "mkdir -p &source_dir.";
x "mkdir -p &target_dir.";
libname srclib "&source_dir.";
%macro scd2(src_table_lib,src_table_name,unique_record_key,tgt_table_lib,tgt_table_name);
/*
src_table_lib: sas libname
src_table_name: sas table name
unique_record_key: unique key, must be a single column not a combination
tgt_table_lib: sas libname
tgt_table_name: sas table name
*/
%put &=src_table_lib.;
def weightedMovingAverage(period, data):
# --- Weighted Moving Average
# data: array, time series data e.g. daily close prices
# period: integer, number of periods from time series array to include in calculation
import numpy as np
# --- get first non nan index
for i in range(len(data)):
Public Function fileNamePath() As String
'--- fileNamePath()
' in: n/a
' out: string, path and name of selected file
' desc: opens an explorer window so the user can select a file. No file type filters are applied.
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
/* setup test data*/
data test_data;
input raw_string & $50.;
datalines;
001-5845-69995
t3sting_%$£ h^%)k
this one should be 100 percent fine
B*FHE`£lDO
;
def clearRAM(print_usage=False):
import os
from hurry.filesize import size
import psutil
import gc
#--- clear ram
gc.collect()
import gc
gc.collect()
*--- define scheduler macro;
%macro egScheduler;
*--- SAS Enterprise Guide Scheduler;
* &today: date when the scheduler was kicked off;
* &rundays: max days scheduler will run continuously;
* &notificationdays: send notification when shceudler reaches this number of rundays;
* &logdir: directory where log fiels are to be saved;
* &job_name: full path to code including name + extension;
SELECT
table_schema
,table_name
,pg_size_pretty(total_bytes) AS total_size
,pg_size_pretty(index_bytes) AS index_size
,pg_size_pretty(toast_bytes) AS toast_size
,pg_size_pretty(table_bytes) AS table_size
FROM (
SELECT
table_schema
def sharpeRatio(returns, periods, rf=0):
# --- Annualised Sharpe Ratio
# returns: array, percentage change values in decimals
# periods: int, annual periods in returns (e.g. days = 252, months = 12)
# rf: decimal, Risk Free Rate generally zero but can be specified as a decimal
import numpy as np
sr = np.sqrt(periods) * ((np.nanmean(returns) - rf) / np.nanstd(returns))