The dataset looks like this:
colx coly colz
0 1 0
0 1 1
0 1 0
Required output:
Colname value count
colx 0 3
coly 1 3
colz 0 2
colz 1 1
The following code works perfectly...
ods output onewayfreqs=outfreq;
proc freq data=final;
tables colx coly colz / nocum nofreq;
run;
data freq;
retain colname column_value;
set outfreq;
colname = scan(tables, 2, ' ');
column_Value = trim(left(vvaluex(colname)));
keep colname column_value frequency percent;
run;
... but I believe that's not efficient. Say I have 1000 columns, running prof freq on all 1000 columns is not efficient. Is there any other efficient way with out using the proc freq that accomplishes my desired output?
I think the most time consuming part in your code is generation of the ODS report. You can transpose the data before applying the freq. The below example does the task for 1000 rows with 1000 variables in few seconds. If you do it using ODS it may take much longer.
Perhaps this statement from the comments is the real problem.
You can tell ODS not to produce the printed output if you don't want it.
One of the most efficient mechanisms for computing frequency counts is through a hash object set up for reference counting via the
suminc
tag.The SAS documentation for "Hash Object - Maintaining Key Summaries" demonstrates the technique for a single variable. The following example goes one step further and computes for each variable specified in an array. The
suminc:'one'
specifies that each use ofref
will add the value ofone
to an internal reference sum. While iterating over the distinct keys for output, the frequency count is extracted via thesum
method.Note
Proc FREQ
uses standard grammars, variables can be a mixed of character and numeric, and has lots of additional features that are specified through options.