BookmarkSubscribeRSS Feed
as_methodology
Fluorite | Level 6

Hello

 

I am trying to compile a report that should look like this in the end:

 

 Q1Q2Q3Q2Mean
Total459452416347418.5
Sex     
    Men205206186177193.5
   Women254246230170225.0
Age     
   15-247477644464.8
   25-49256248230196232.5
   50+129127122107121.3

 

On the one hand I need to stack the variables (Sex, Age) which I know how to do in proc tabulate but can't do in proc report. And on the other hand I need to calculate the mean of the four quarters, which I know how to do in proc report but not in proc tabulate.

 

Any ideas how to create such a report.

 

Many thanks in advance, Simon

9 REPLIES 9
Reeza
Super User
What does your input data look like? That determines how easily this can be built. Is Q1, Q2, Q3 variables or are those quartiles? And why are there two Q2s?
as_methodology
Fluorite | Level 6

Dear Reeza

 

Thanks for the reply. I have individual data. That is every observation has a single line:

YearQuarterIDSexAge
2018Q11234M15-24
2018Q22645M15-24
2018Q31245M25-49
2018Q48654F50+
2018Q15423F15-24
2018Q25431F15-24
2018Q398425M25-49
2018Q424343M25-49
2018Q14534M15-24

Quarter is the part of the year (Jan, Feb, Mar = Q1, Apr, May, Jun=Q2 and so on). Of course the second Q2 should read Q4. Mean should then be the average of the four quarters (Q1+Q2+Q3+Q4)/4.

 

Best, Simon

Reeza
Super User

There's no values in that data set...what are the statistics/mean of?

as_methodology
Fluorite | Level 6

We have the number of observations. That is in total we have 459 observations in the first quarter.

 

The idea is to get the average of the four quarters:

 

 Q1Q2Q3Q2Mean
Total459452416347418.5 = (459+452+416+347)/4
Reeza
Super User

@as_methodology wrote:

We have the number of observations. That is in total we have 459 observations in the first quarter.

 

The idea is to get the average of the four quarters:

 

  Q1 Q2 Q3 Q2 Mean
Total 459 452 416 347 418.5 = (459+452+416+347)/4

Ok, with this new information, my previous answer is incorrect. I'm not sure how to calculate the mean of a count within any of the summary procs so I suspect you're going to need to pre-summarize your data and use PROC REPORT to display it. 

Tom
Super User Tom
Super User

@as_methodology wrote:

We have the number of observations. That is in total we have 459 observations in the first quarter.

 

The idea is to get the average of the four quarters:

 

  Q1 Q2 Q3 Q2 Mean
Total 459 452 416 347 418.5 = (459+452+416+347)/4

If you always have 4 quarters then mean is just grand total divided by 4.

 

as_methodology
Fluorite | Level 6

That is correct. However, I do not know how to calculate this in SAS.

ballardw
Super User

Sometimes it is easiest to pre-summarize the data values and then use Proc Report/Tabulate/Print just to display the result.

 

Tabulate in general does not do calculation using the results of other statistics (limited ability with PCTSUM type statistics).

 

Example starting data is always helpful.

Reeza
Super User

I think this is exactly what you want, using PROC TABULATE. You can map it to your data to see how it should work, but since you didn't provide sample data I worked off sashelp.heart.

Part of the key here is the ALL keyword, that will do the summaries.

 

 

proc tabulate data=sashelp.heart;
class status sex smoking_status;
var systolic;
table all (status) (sex), (smoking_status all)*systolic*Mean ;
run;

@as_methodology wrote:

Hello

 

I am trying to compile a report that should look like this in the end:

 

  Q1 Q2 Q3 Q2 Mean
Total 459 452 416 347 418.5
Sex          
    Men 205 206 186 177 193.5
   Women 254 246 230 170 225.0
Age          
   15-24 74 77 64 44 64.8
   25-49 256 248 230 196 232.5
   50+ 129 127 122 107 121.3

 

On the one hand I need to stack the variables (Sex, Age) which I know how to do in proc tabulate but can't do in proc report. And on the other hand I need to calculate the mean of the four quarters, which I know how to do in proc report but not in proc tabulate.

 

Any ideas how to create such a report.

 

Many thanks in advance, Simon


 

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
  • 9 replies
  • 935 views
  • 0 likes
  • 4 in conversation