prg below tries to count the instances of variables.
%macro freq(dsn=,variable=,freq=,label);
proc freq data = &dsn;
tables &variable;
run;
%mend;
%freq(dsn=fff,variable=ggg);
prg below tries to count the instances of variables.
%macro freq(dsn=,variable=,freq=,label);
proc freq data = &dsn;
tables &variable;
run;
%mend;
%freq(dsn=fff,variable=ggg);
you should be able to do this by adding a format and print procedure. I have tested this and I believe it achieves what you are looking to accomplish.
%macro freq(indsn=,variable=,freq=,label);
/* Create a new format or label when a value falls between
0 and the user defined frequency. */
proc format;
value fmt 0-&freq. = "&label.";
run;
/* Run the frequency procedure and suppress the output
to a temporary data set. */
proc freq data = &indsn;
tables &variable / noprint out=temp;
run;
/* Print the temporary data set and format the Count
variable (which was created in the freq procedure)
to the format, fmt, that we created. Finally, print only
records with a frequency less than the user defined
frequency. */
proc print data=temp noobs;
format count fmt.;
where count le &freq.;
run;
%mend;
With your recent edit you will be able to accomplish this with a data step and an if statement.
%macro freq(indsn=,variable=,freq=,label);
/* Run the frequency procedure and suppress the output
to a temporary data set. */
proc freq data = &indsn;
tables &variable / noprint out=temp;
run;
/* Assign variable a new name if its frequency equals the
user defined frequency and only keep records with a count
less than or equal to the frequency. */
data temp;
set temp;
if count le &freq.;
if count = &freq. then &variable. = &label.;
run;
/* Print only the &variable variable. */
proc print data=temp noobs;
var &variable.;
run;
%mend;