philihp.com

Tag: SAS

Automatic Base SAS Library Assignments

If you stick a file named autoexec.sas in the directory where SAS is installed, it will run automatically when SAS starts up. By default, this place is C:\Program Files\SASHome\SASFoundation\9.3. This has worked since at least SAS 8.2, probably before. I like to use my Windows desktop as a temporary staging area, so I have my [...]

Finding the Center of US Counties in SAS

I had a problem where I needed the center longitude and latitude of each US county. SAS comes with some datasets containing map data in the format of tables that trace a line around the borders of counties. I was interested in the MAPSGFK.US_COUNTIES dataset, which has data that looks like this: The State and [...]

Bayesian Averaging in SAS

Hypothetical situation, lets say you’ve got a list of movies that you want to rank in a website or a report or something, and you have user-submitted ratings for them, but some are more popular than others, so your data looks like this: data ratings; input name $ rating; datalines; Lincoln 9 Lincoln 8 Lincoln [...]

Selecting Rows from the Last 5 Years in SAS

I was asked recently in a Q&A, “how to select the last 5 years worth of data from a table in SAS?” One way of doing it is by selecting the data with a Proc SQL query similar to the following, and something similar could also be done in a data step: PROC SQL; create [...]

How to write your own Custom SAS Functions

Since SAS 9.1.3 we’ve had the ability to write our own SAS call procedures and functions using PROC FCMP (short for “Function Compiler”). A simple example of this is as follows: proc fcmp outlib=work.funcs.temp; function findname(uri $) $200; length name $200; rc = metadata_getattr(uri,’Name’,name); return(name); endsub; run; After running this, we should have a custom [...]

Blackjack Dealer Odds

Below is a graph and table showing the exact odds of a dealer’s end-hand given his show card. One thing to keep in mind when playing: if the dealer is dealt a show-card of an ace and you’re being asked to hit or to stand, you know that his hole card is not a ten. [...]

METAOUT=DATA error in SAS Enterprise Guide

The Symptom In Enterprise Guide 4.3, I kept running into this problem. Whenever I had a remote server, and a library created on it, I couldn’t create a new table in the library without first creating a stub table metadata object. I couldn’t take a Query Builder’s output going to WORK, and instead change that [...]

How to use a SWITCH Statement in SAS

In SAS, the switch statement is called a SELECT statement. SELECT <variable | expression>   WHEN(condition) …   <WHEN(condition) …>   <WHEN(condition) …>   …   <OTHERWISE …> END; http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm When a select expression is given, it evaluates this and does a relative jump, which is similar to the optimization done by a C or Java compiler in a switch [...]

Using a SAS LIBNAME’s connection in Pass-through

New to SAS 9.3 is the ability of Proc SQL’s ability to reuse the database connection from a LIBNAME statement in a direct pass-through query. Ability to Reuse the LIBNAME Statement Database Connection The database connection that is established with the LIBNAME statement can be reused in the CONNECT statement. The keyword USING has been [...]

How to Create an Empty SAS Dataset

If you were to do this in SAS to create an empty SAS dataset: data mytable; run; It would actually create a dataset with one row. The data step cycles through once, hits the end (run), outputs a row, then comes back and finds it has no more rows to process so it stops. To [...]