BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Konstantin123
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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

3 REPLIES 3
FreelanceReinh
Jade | Level 19

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."

ballardw
Super User

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.

 

Ksharp
Super User
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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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