DATA Step, Macro, Functions and more

proc freq how display all lines

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

proc freq how display all lines

I have data set with:
proc format;
        value my_f 1="A"
                          2="B"
                          3="C"
                          4="D"
                          5="E";
run;

 

And i have programm

 

proc freq data=temp;
         tables my_tables /nocum
         out = temp_2;
run;


Result:
Name COUNT PERCENT
A           1          10
C           9          90


But i need:

Name COUNT PERCENT
A          1          10
B          0          0
C          9         90
D          0         0
E          0          0


Accepted Solutions
Solution
‎04-07-2016 01:42 PM
Trusted Advisor
Posts: 1,115

Re: proc freq how display all lines

Hello @Konstantin123,

 

Try this:

data allcat;
do name=1 to 5;
  output;
end;
run;

data want;
merge temp_2(in=t)
      allcat;
by name;
if ~t then do;
  count=0;
  percent=0;
end;
run;

Please note that I used NAME as the variable name. In your PROC FREQ step it's called MY_TABLES, but in your output it appears as "Name."

View solution in original post


All Replies
Solution
‎04-07-2016 01:42 PM
Trusted Advisor
Posts: 1,115

Re: proc freq how display all lines

Hello @Konstantin123,

 

Try this:

data allcat;
do name=1 to 5;
  output;
end;
run;

data want;
merge temp_2(in=t)
      allcat;
by name;
if ~t then do;
  count=0;
  percent=0;
end;
run;

Please note that I used NAME as the variable name. In your PROC FREQ step it's called MY_TABLES, but in your output it appears as "Name."

Super User
Posts: 10,516

Re: proc freq how display all lines

This should get you started:

proc tabulate data=temp;
   class my_tables/ preloadfmt;
   format my_tables my_f.;
   table my_tables,n='Count' ColPctN='Percent'
    / printmiss misstext='0';
run;

The Preloadfmt only works with limited procedures, Report, Means and Tabulate, to show the appearance of formatted values not in your data. The Printmiss is one of a couple ways to get the missing values printed in the output. Misstext to show 0 instead of default period for missing values since you don't have anything to actually count.

 

Super User
Posts: 9,682

Re: proc freq how display all lines

[ Edited ]
Use proc tabulate or  proc freq + weight w / zero .



proc format;
        value my_f 1="A"
                          2="B"
                          3="C"
                          4="D"
                          5="E";
run;
data have;
input my_tables ;
cards;
1 
2
2
;
run;
options missing=0;
proc tabulate data=have;
class  my_tables /preloadfmt;
format my_tables my_f.;
table my_tables ,n pctn/printmiss;
run;





/**************************************/

data key;
do my_tables=1 to 5;
 output;
end;
run;
data want;
 set have(in=ina) key;
 w=ina;
run;
proc freq data=want;
 table my_tables;
 weight w/zero;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 219 views
  • 2 likes
  • 4 in conversation