SAS Enterprise Guide as a Programming Aid – Finding Functions

While I believe SAS Enterprise Guide was developed to make statistical analysis easier for non-programmers, it is also a useful tool for experienced programmers. Often, I find myself thinking, “I KNOW there is  a function that does that ….” but I just can’t remember exactly what it is.

Take today as an example. I have data that comes in a date-time format. You know “October 22, 2012 13:34:58” . I want it broken out into the date part and the time part, for reasons I will explain tomorrow. I happened to be using Enterprise Guide, so I went in the TASKS menu to DATA and then QUERY BUILDER. computed window

I clicked on COMPUTED COLUMNS (see window at right)

I clicked on NEW (for a new computed column)


Then clicked NEXT

and here I was.

In creating an expression, this particular feature of Enterprise Guide is most helpful if you have some programming experience.

expression windowFor example, I knew that there was some function that would select the date part of a date-time value and I was pretty sure there was also a function to select the time part.

So … in the window to build an advanced expression, I clicked on the + next to functions (the plus sign) and it drops down a whole list of functions to choose from.

This is really only helpful if you’ll recognize it when you see it. In my case, I scroll down and see the DATEPART function. Clearly, that’s what I’m looking for.

If you are not sure, you can click on the function and the right window pane will show the description and syntax.

So … I double-click to move the DATEPART function into my advanced expression. If you have forgotten your variable names, clicking on the + next to your data set (the thing that looks like a spreadsheet with a red ball in the corner), will drop down all of the variable names, and you can double-click on that to move it up as an argument of the function.

function list with datepartAfter I have created this variable with the date, I can go back through the same steps and find out that there is another function called, not surprisingly, TIMEPART.  There is a place for creativity in programming, but naming is not the place.

Having created my two variables with date and time as separate values, I can now go back to programming.

My life is complete.

On a random note, I signed up for NaBloPoMo which I thought was about pledging to blog every day for a month, which I thought was cool, but it turns out there are prompts you are supposed to blog about. The one for today is what is your favorite quotation and why.

Regarding statistics, this has to be my favorite quote, attributed to Josiah Stamp,

“”The government are very keen on amassing statistics. They collect them, add them, raise them to the nth power, take the cube root and prepare wonderful diagrams. But you must never forget that every one of these figures comes in the first instance from the village watchman, who just puts down what he damn pleases.”



Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *