0

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);
Apache11
  • 189
  • 11
  • What do you mean by 'assign a label and display it' ? Also, this is not a code-on-request service - please make an effort to do this yourself and ask a specific question if you get stuck at a particular step. – user667489 Sep 19 '16 at 13:25

1 Answers1

0

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;
J_Lard
  • 1,083
  • 6
  • 18
  • As this stands this is not a very good answer. While providing code to answer questions is generally a good thing, you should answer the question in more than just code, by describing how your answer solves the problem and how it works. – Joe Sep 19 '16 at 15:16
  • @Joe i need to code to see how many times a vriable value is repeated it the repeated value is equal to the freq= 'parameter ' then assign a diff label/value "XYZ" to it. so in the out put it should be the new label displayed instead of the repeated variable value. – Apache11 Sep 19 '16 at 15:26
  • @Joe Sorry for the vague answer, I have updated to provide a bit more clarity as to what the code is doing. – J_Lard Sep 19 '16 at 15:45
  • Thanks, J_Lard. It might be better with some not-comments details (i.e., plain english explanation), but this is better for sure than just code. – Joe Sep 19 '16 at 15:46