Skip to content

Instantly share code, notes, and snippets.

@Benjit87
Benjit87 / customsapparenhance
Created October 3, 2014 11:25
Enhancing SAP PA Summary for Custom R
#Create your own S class, pass your results as object, use your own summary function
Summary_Printer <- function(obj1) UseMethod("Summary_Printer")
Summary_Printer.default <- function(regression,sandwich)
{
printer <- NULL
printer$regression <- regression
printer$sandwich <- sandwich
class(printer) <- "Summary_Printer"
printer
}
%let query=hello;
%let likequery=%sysfunc(cat(%str(%%),%str(&query),%str(%%)));
%put &query; *Will appear as hello in log;
%put &likequery; *Will appear as %hello% in log;
proc print data=test;
where x like "&likequery";
run;
@Benjit87
Benjit87 / Datastage Custom C++
Created July 30, 2013 08:36
Simple Datastage Custom C++
APT_TimeStamp dateofbirth(in0.Dob,"%yyyy%mm%dd%hh%nn%ss%SSSSSS",true); // APT_Timestamp to convert char to timestamp (see the reference card for more info)
if ( !dateofbirth.isValid() ) { recOk = false; } else { out0.Dob = dateofbirth;} // check if the current record contains a valid timestamp
out0.Name = in0.Name; // assign the column from the 1st input port to the 1st output port which is the results port
out0.Country = in0.Country;
if ( lowercase == "yes" ) { out0.Country.toLower(); } // if the string property (as defined in the property tab) of lowercase is yes , output should be lowercase
out0.Region = in0.Region;
out0.Region.trimWhitespaceLeadingTrailing(); //this is actually a datastage macro, you can use setPadChar and trimPadding to trim (see reference card). To see how to conversion (using some C precompilers) is being applied you can take a look at the generated C++ code after generation
@Benjit87
Benjit87 / opencvconvexdefect
Created February 13, 2013 14:14
/* http://benjithian.sg/2013/02/simple-convex-defect-opencv/ Simple Convex hull with Convex Defect. Simple stuff. */
/*
http://benjithian.sg/2013/02/simple-convex-defect-opencv/
Simple Convex hull with Convex Defect. Simple stuff.
*/
#include <stdio.h>
#include <curl/curl.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
/*
http://benjithian.sg/2012/12/simple-convex-hull-opencv/
Simple Convex hull. Simple stuff.
*/
#include <stdio.h>
#include <curl/curl.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
/*
Inspired by Rick Wicklin's <a href="http://blogs.sas.com/content/iml/2012/12/14/a-fractal-christmas-tree/">SAS Christmas Tree</a>, i decided to create my own tree using Base SAS to generate the data and then using JMP to visualize the data in bubbleplot.
http://benjithian.sg/2012/12/sas-jmp-christmas-tree/
*/
/* Snow generator */
%macro snow_generator(density,filename);
data snow;
drop i;
do i = 1 to &density;
/*
http://benjithian.sg/2012/12/simple-background-subtraction/
Simple Background Subtraction. Simple stuff.
*/
#include <stdio.h>
#include <curl/curl.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
:: Open the folder that contains the sas files
cd "C:\Users\Benji_Thian\Desktop\SAS_and_OTHERS\Scheduling"
:: Use Base SAS to call the javasas.sas program in batch mode with any specificed settings u want
"C:\Program Files\SASHome\SASFoundation\9.3\sas.exe" -BATCH -NOTERMINAL -CONFIG "C:\Program Files\SASHome\SASFoundation\9.3\nls\en\sasv9.cfg" -set classpath "C:\Users\Benji_Thian\workspace\test\bin" -SYSIN "javasas.sas"
/* Use SAS to call Java Object *
* http://benjithian.sg/2012/12/sas-with-java/ */
/* Sample Data from Google Chart API*/
data Work.test;
infile datalines missover;
input Topping $ Slices $;
datalines;
Mushroom 3
Onions 1
/* A Simple Java class just to write a google chart html when called by BASE SAS*/
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Chart {
HashMap<String,Integer> map = new HashMap<String,Integer>();
public Chart()