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;

1 Comments:

Anonymous Anonymous said...

I'm not sure exactly why but this weblog is loading extremely slow for me. Is anyone else having this issue or is it a problem on my end? I'll check back later on and see if
the problem still exists.

Also visit my web page :: hotel escort

11:07 am  

Post a Comment

<< Home