Dick Duck's SAS tips

This is the nest where I keep my SAS eggs. It's all here... Arrays, control loops, links to online SAS resources, you name it.

Friday, March 10, 2006

Freq's a wreck

proc freq is very useful if you want to see a quick frequency distribution of some variables on screen. But often you want to save that distribution, and use it as the basis for some calculations, or merge it with another file. For instance, you might have a file with all the candidates' item marks and you want to derive a file containing the mark distribution for all the items. To view them on screen you would do something like:

proc freq data = marks;
by item;
tables mark mark_adjusted;
run;
You would think that if you did the following, you would save these results to the file 'mark_distribution':

proc freq data = marks noprint;
by item;
tables mark mark_adjusted;
output out = mark_distribution;
run;
But output is only meant to save to file certain statistics, like the mean and so on. Since you didn't specify any, freq will throw a wobble. Here's how to do what you really want:

proc freq data = marks;
by item;
tables mark / noprint out = mark_distribution;
tables mark_adjusted / noprint out = mark_adj_distribution;
run;
Of course, if you want these distributions combined you will have to merge them:

proc sort data = mark_distribution; by item mark; run;
proc sort data = mark_adj_distribution; by item mark; run;
data mark_distribution;
merge mark_distribution mark_adj_distribution;
by item mark;
run;
proc datasets; delete mark_adj_distribution; run;

Tuesday, March 07, 2006

Bind those keys!

When you hit F9, you'll see a window with all the keybindings (shortcut keys to you and me). F12 is usually empty, and I like to put the following in:

F12     output; clear; log; clear; wpgm
This clears your output window and your log window and then returns you to the editor window. I like to hit F12 before I submit any new commands, so I don't have to search and scroll through the log and the output, but start with nice shiny new ones.

Thursday, March 02, 2006

Widget

Install this widget on your dashboard, and you'll only be ever one click away from my sage advice...
dick duck's sas tips widget