BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
adrnneadriana
Calcite | Level 5

Hi,

 

I have a format with all values.  How do I get counts and % for these values from a dataset  ? If the values are not present in dataset, i need count and percent as 0

 

Example:

proc format library = work;
 value $car_type
  "Hybrid" = "Hybrid Drivetrain"
  "SUV" = "Sports Utility Vehicle"
  "Sedan" = "4-door Sedan"
  "Truck" = "Pickup Truck"
  "Wagon" = "Station Wagon"
  "Testc" = "Test value"
 ;
run;


But when I run proc feq, I need frequency and percent for type as Testc. Even though it is 0

 

proc freq data = sashelp.cars;
tables type / missing;
format type $car_type.;
run;

I came across 1 article where it says its not possible, but it dated 2015. So wondering if there is any new feature added to SAS. I'm using SAS release: 9.04.

 

Solved: How To - Create Count of Variable with Missing Val... - SAS Support Communities

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I don't think PROC FREQ can do this without some manipulation of the data set. However, PROC SUMMARY/PROC MEANS can do this, example:

 

proc summary data=sashelp.cars completetypes;
    class type/preloadfmt;
    format type $car_type.;
    var invoice;
    output out=_stats_ n=n;
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I don't think PROC FREQ can do this without some manipulation of the data set. However, PROC SUMMARY/PROC MEANS can do this, example:

 

proc summary data=sashelp.cars completetypes;
    class type/preloadfmt;
    format type $car_type.;
    var invoice;
    output out=_stats_ n=n;
run;
--
Paige Miller
adrnneadriana
Calcite | Level 5
Thank you, how about if my input dataset is empty ?

In that case, I'm not getting the pre loaded formats
ballardw
Super User

Different procs different possibilities:

 

proc tabulate data=sashelp.cars;
   class type/ preloadfmt;
   format type $car_type.;
   tables type,
          n colpctn
          /printmiss misstext='0'
   ;
run;
proc report data=sashelp.cars completerows;
   columns type ( n pctn);
   define type / group format=$car_type. preloadfmt ;
   define pctn /format=percent8.2;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 261 views
  • 0 likes
  • 3 in conversation