Friday, October 28, 2016

How to set special characters in SAS Base code

If you ever end up having a sas variable, which contains special characters in it, and you want to split them into each separate variable, you need to use a ascii number equivalent to required special character,and at x at the end of the string.
For example, if the special character is tabulator:

data test;
a="column1 column2 column3"; column1=scan(a,1,'09'x); column2=scan(a,2,'09'x); column3=scan(a,3,'09'x); run; In ASCII table, '09'x is a ascii equivalent to tab character.

Saturday, October 22, 2016

How to round the number up to 2 digits in Javascript

Sometimes you need to round up the number up to 2 digits. For example, you calculation has to show a result in currency.

There are two solutions to use on internet:

1) Use Math.random function.

var a=123.4567;


However, this is not really good, as for example in case of
var a=1.005;
Math.random(a*100)/100 results into 1 instead of 1.01.

2) use toFixed(2)

However, it is more secure option to use a.toFixed(2), which would return element as fixed 2 decimal value

Friday, January 15, 2016

How to download/upload a SAS dataset from server to your local machine

There is a neat way the EG offers you to download SAS datasets.
Under a menu bar, there are a options

  • "Tasks" - "Data" - "Upload Data Files to Server" and 
  •  "Tasks" - "Data" - "Download Data Files to PC" 
In case of "Download Data Files to PC", you need to choose a dataset you want to transfer.

My humble suggestion is to first subset the original dataset to a temporal dataset you exactly need, and download only the temporal dataset.

Detailed screenshots will follow...

Thursday, October 22, 2015

Changing system time on Virtual Box Virtual machines

Once upon a time I needed to change the system time of the virtual machine to test its behavior at specific date/time. To do that, you can use the following commands:
VBoxManage setextradata "YOURVIRTUALMACHIENNAME" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
VBoxManage modifyvm "YOURVIRTUALMACHIENNAME" --biossystemtimeoffset -36288000000
This script above returns the time 420 days in the past. Note to myself: Change this post to add also other useful commands, including the one to switch existing virtual hard disk properties (static to dynamic, its size, etc)

Monday, October 19, 2015

Javascript - Take care of Regular Expressions

These text here is my summary of things I learned while reading the eloquentJS book. In order to understand the issues mentioned in a book better, I have created a different examples.

Take care when using Regular expressions in Javascript.

1) lastIndex is not refreshed, when using global regular expressions for multiple exec calls.

var whitespace = /\s/g;
var test1="This is the first test";
var test2="This is the second test";
var test3="This is the third test";
var test4="This is the fourth test";

document.getElementById("result").innerHTML="after test1:"+whitespace.lastIndex;
after test2:"+whitespace.lastIndex;
after test3:"+whitespace.lastIndex;
after test4:"+whitespace.lastIndex;

Thursday, October 8, 2015


It often happens to me that I have a part of a code which I dont understand, neither know how to search for it.
These cases are those when you look for some operator shortcuts in programming codes.
For example, (+) sign in PL/SQL. How to find this?
Through answers of good old StackOverflow community, I came up to symbolhound .
Perfect search engine for exactly those cases!

Friday, July 17, 2015

Dynamically assign fileref to external file

Sometimes, you might want to assign fileref to external file which path you get to know during some complex data manipulations. In that case, filename statement is difficult to use as filepath you need to know in advance. Along with FILENAME statement, SAS offers also FILENAME function, which you can use within the DATA step.

SAS Base

data test;

data _null_;
  set test;

data csvData(drop=path);
  infile fid;
  input ...

SAS Data Integration Studio

Let's assume that you already have SAS dataset created that contains path to csv file. Then you need to:
  • add "User Written Code" transformation (under "Data->User Written Code"),
  • connect SAS dataset (that contains path to csv file) to "User Written Code transformation".
  • Go to "User Written Code" properties, tab "Code" (keep "Code generation mode: User Written Body"), and in the code body write the following text right above %rcSet(&syserr... (it is sometimes hard to see, but automatically generated code has a greyish background, and your code has complete white background):
        data null; 
          set &_INPUT.; 
  • now create a new "External File", set metadata you want (I assume you know what you expect as a format of the csv file), and
  • under "External File"s Properties, tab "File Location", under "File name:", write simply "fid" (without quotes), and under "File Name Quoting" on the same tab, choose "No quotes around file name".