1
votes

I have a data set with a number of records (the contents of which are irrelevant) and a series of flag variables at the end of each record. Something like this:

Record ID   Flag 1   Flag 2   Flag 3
1           Y
2                    Y        Y
3
4
5
6           Y        Y

I would like to create a printed report (or, ideally, a data set that I could then print) that would look something like the following:

Variable   N    % Not Missing
Flag 1     6    33.33333
Flag 2     6    33.33333
Flag 3     6    16.66666

I can accomplish something close to what I want for one variable at a time using Proc Freq with something like this:

proc freq data=Work.Records noprint;
    tables Flag1 /out=Work.Temp;
run;

I suppose I could easily write a macro to loop through each variable and concatenate the results into one data set... but that seems WAY too complex for this. There has to be a built-in SAS procedure for this, but I'm not finding it.

Any thoughts out there?

Thanks!

1

1 Answers

1
votes

Welcome to the fabulous world of Proc Tabulate.

PROC TABULATE is the procedure to use when PROC FREQ can't cut it. It works similarly to PROC FREQ in that it has table statements, but beyond that it's pretty much on steroids.

data test;
input RecordID   (Flag1   Flag2   Flag3) ($);
datalines;
1 Y . .
2 . Y Y
3 . . .
4 . . .
5 . . .
6 . Y Y
;;;;
run;
proc tabulate data=test;
class flag1-flag3/missing;
tables (flag1-flag3),colpctn;  *things that generate rows,things that generate columns;
run;

Unfortunately it's not easy to hide the blank rows without using some advanced style tricks, but if you don't mind seeing both rows this works pretty well.