Posts

Showing posts with the label SAS

Create your own formats and informats

create new formats and informats, and some typical examples Paper (PDF) Wiki Article

Browse through file system with SAS Base

It often happens that task comes to implement certain SAS program on a machine which internal file system is not available. These files can be useful to list files and folders, and read files, which have access granted to local user used to execute SAS programs (usually sassrv user) In order to browse through file system where SAS is running, the following two SAS programs can be very useful: Listing Files and Folders of the system hosting SAS Read Files and display it in SAS Output as text P.S. Second example is taken from SAS website, but always extremely hard to find.

SAS and Web/REST Service Calls

SAS offers a possibility to communicate with Web Services and REST services using a couple of tools. Most important products of SAS required to properly communicate with Web Services/REST Services are: PROC SOAP PROC HTTP XML Library Engine (xmlv2) The following examples show how are these coupled together: Calling and Parsing the Web Service using SAS Calling and Parsing the REST service using SAS

How to extract filename and extension from the absolute path in SAS

This is very simple problem in SAS, but somewhat nowhere on internet written. You can use scan function to catch last occurrence of string.

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: In ASCII table, '09'x is a ascii equivalent to tab character.

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

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

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

Reading multiple external files 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. 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:

Error: Invalid business key defined

In SAS DI Studio, when you try to add the column as Business Key which is already selected as a Detect Changes, you will get the error: Error: Invalid business key defined In order to resolve that, you need to remove whatever business keys you want to define from " Detect Changes " tab, it error is gone.

What makes SAS Enterprise Guide not a mature application ...

Ok, before I start expressing my opinion about SAS Enterprise Guide and SAS Base Programming, I would like to make a quick introduction of my technical experience and expertise. Throughout 7-8 years of my professional life, I have been using in great extent software tools like MATLAB, and have been programming enterprise applications in Java/Spring. In last 6 months I am introducing myself to SAS World. Version I am working on is SAS Enterprise Guide 9.4. For a system that still uses programming model (SAS Base) of 80s, a graphical interface which visually shows how the process is being executed is a great refreshment. There are many options on dealing with data and doing analysis on it, making it very comfortable tool to easily build a large data manipulation process. Basic Application use issues: "Object reference not set to an instance of an object". It relatively often happens (every 4 days of 8h daily use of SAS Enterprise Guide) that the file you think yo...