Tag Archives: SAS

Using SUBSTR on the left of an assignment in SAS

This is a pretty cool feature, and as far as I know it’s unique to SAS and Perl. In SAS, you can have a substr to the left of an assignment. stringDate=’29MAR1984′; substr(stringDate,3,3)=’FEB’; This avoids potentially awkward situations like this: stringDate=’29MAR1984′; stringDate=substr(stringDate,1,2)||’FEB’||substr(stringDate,6,4); The bounds don’t have to be static. Lets suppose we have a dataset […]

Installing SAS 9.4 on Ubuntu 14.04

Officially SAS does not support Ubuntu Linux as a platform, in spite of it being the most popular desktop distribution. It will run, but there are two things you need to do: First, reconfigure Ubuntu not to use dash. The SAS Deployment Wizard will freeze when you first click “Next” during the install if you […]

SAS Macro Variable Resolution Timing

I thought this was neat and quirky. The implications of it are important, too. When you assign a macro variable in SAS, it doesn’t resolve immediately. It resolves It will also warn you if the variable doesn’t exist yet, too. %let x = &y; %let y = z; %put &x; Will output z Even though, […]

Using Secure HTTPS (SSL) URLs in SAS on Linux

Out of the box SAS 9.4 is not configured to use SSL on Linux x64. If you try to do this, you’ll get the error ERROR: SSL Error: Missing CA trust list This happens because when SAS gets the SSL certificate from the server, it sees that it’s signed by a Certificate Authority, but it […]

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 FilesSASHomeSASFoundation9.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 […]

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. […]