Programming the statistical procedures from SAS

Proc means - number of items

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

Proc means - number of items

Hello,

 

My data is as follow:

No of obser.png

 

I intend to use proc means in order to calculate number of variables that relate to this table. If I want to calculate the Number of observations that I use function N in proc means. Which function should I use to calculate the number of firms?

 

Thanks for any help

 

Yael


Accepted Solutions
Solution
‎03-28-2017 11:58 AM
Grand Advisor
Posts: 10,043

Re: Proc means - number of items

Proc Means will not do what you are requesting in a single pass with the data you have.

Options would be to modify the data a bit to include a variable that is assigned a value that could be processed with either N or sum. For tables such as you show I would switch from summary to a report procedure:

data want;
   set have;
   by firm;
   FirmCount = first.firm;
run;

proc tabulate data= have ;
   class ff status;
   var Firmcount;
   table ff,
         status=''*n=''
         /style=[Pretext='Observations'];
   table ff,
         status=''*FirmCount=''*sum=''*f=best5.
        /style=[Pretext='Firams'];
run;

 

Other options would be summarize the data twice once with firm as class variable (or use Proc Freq) and then summarize the result again.

 

In the future to get better responses post input, and if possible output, data in the form of a data step so that we can duplicate what you have. Not many people are going to type in your data to test code. An existing SAS data set can be turned into data step using: Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

View solution in original post


All Replies
Solution
‎03-28-2017 11:58 AM
Grand Advisor
Posts: 10,043

Re: Proc means - number of items

Proc Means will not do what you are requesting in a single pass with the data you have.

Options would be to modify the data a bit to include a variable that is assigned a value that could be processed with either N or sum. For tables such as you show I would switch from summary to a report procedure:

data want;
   set have;
   by firm;
   FirmCount = first.firm;
run;

proc tabulate data= have ;
   class ff status;
   var Firmcount;
   table ff,
         status=''*n=''
         /style=[Pretext='Observations'];
   table ff,
         status=''*FirmCount=''*sum=''*f=best5.
        /style=[Pretext='Firams'];
run;

 

Other options would be summarize the data twice once with firm as class variable (or use Proc Freq) and then summarize the result again.

 

In the future to get better responses post input, and if possible output, data in the form of a data step so that we can duplicate what you have. Not many people are going to type in your data to test code. An existing SAS data set can be turned into data step using: Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Contributor
Posts: 69

Re: Proc means - number of items

I accept your remark, thanks a lot!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 98 views
  • 1 like
  • 2 in conversation