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".

Redirect libref to WORK library in SAS

Imagine you have a SAS Enterprise Guide Project, where you have been using a libref (let's name it "SAVE") very often. However, now you want to switch it in specific occassion turn to WORK library so that it does not require a specific folder for SAS datasets to be saved. Also, you would still like to have the LIBNAME statement for SAVE libref, so that you can switch easily from WORK libref to specific path. so, the following two solutions you can use:
LIBNAME save %sysfunc(quote(%sysfunc(pathname(work)))) ;
the second way to do it is the following:
%let workLocation=%sysfunc(getoption(work));
libname SAVE "&workLocation.";

Read multiple external files into single dataset in SAS

Sometimes you get to have a multiple external files, which you need to read in SAS.
For further manipulation, it looks good if these data could all be gathered in the same dataset, from which then usual data manipulation queries could be performed on.

%let dirname =/path/to/folder/to/scan;
%let ext=csv;

data dirlist (keep=filepath fext fname);
 if rc eq 0 then do;
  length filepath $256; 
  do i=1 to count;
       if upcase(fname) ne upcase(fext) and upcase(fext) eq upcase("&ext.") then do;

data all_text;
  length myfilename $100;
  set dirlist;
  infile dummy filevar = filepath length=reclen end=done missover delimiter=';' dsd;
  do while(not done);
    myfilename = filepath;
    input a $ b $ c $ d $;  

proc print data=all_text;
Now, if you would like to conditionally to read multiple files that have different structure, you can conditionally change the input statement. Let's say that file has the different structure if its name ends with "d" character:
data all_text;
  length myfilename $100;
  set dirlist;
  infile dummy filevar = filepath length=reclen end=done missover delimiter=';' dsd;
  do while(not done);
    myfilename = filepath;
 if prxmatch("/d.&ext.$/",trim(fname)) then do;
 input un1 $ un2 $ un3 $ a $ b $ c $ d $;
 drop un1 un2 un3;
 else do;
    input a $ b $ c $ d $;