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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

yael
Quartz | Level 8

I accept your remark, thanks a lot!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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