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

Hi. Can anyone help me with the following:

 

I have about 10 datasets. I want to report N, Mean, Median (95%) for one "numeric variable" (a different numeric variable for each dataset, for example, one data contains age, another contains cost etc. ) by one "CLASS" (for example, race for the first data, year for the second), the output should look as below:

Variable                  Statistics                 

Age

     White                 N                 4

                               Mean           45

                               Median        43 (42 - 45)

     Black                 N                  4

                               Mean           44 

                               Median        40 (39 - 45)

Cost

    2001                  N                  3

                              Mean           90

                              Median        120 (100 -200)

   2002                   ETC.

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@Emma8 wrote:

Thank you. But this isn’t what I want. I will use proc summary or proc means, but I want to know the sas codeabout looping over multiple dataset and save the results and report as one table report.


You haven't described a problem that would benefit from any looping.  You want to calculate different statistics from different tables.  So do that.  You might find it useful to put the results into a dataset that will make it easy to produce the report you show.  Why not follow the model shown in this classic paper:  https://www.lexjansen.com/pharmasug/2010/TT/TT05.pdf

 

View solution in original post

6 REPLIES 6
ballardw
Super User

My first question would be if all this needs to be in a single report why is it in different data sets? And is that desired output supposed to be a single table??

 

 

 

 

Emma8
Quartz | Level 8

Thank you.

I have many datasets but want to report just as one table.

Reeza
Super User

There are two approaches, one is to combine the data and then summarize or to summarize and combine the results.

You also need to break down your variables by different categories/levels it seems. ie Cost is broken down by year whereas age is broken down by some sort of colour it seems.

I would probably summarize all my data sets individually and then combine them since there are different criteria. PROC MEANS is the swiss army knife for general statistical summaries.

Here's a tutorial on calculating summary statistics and how to save those values to datasets.

https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas

 


@Emma8 wrote:

Hi. Can anyone help me with the following:

 

I have about 10 datasets. I want to report N, Mean, Median (95%) for one "numeric variable" (a different numeric variable for each dataset, for example, one data contains age, another contains cost etc. ) by one "CLASS" (for example, race for the first data, year for the second), the output should look as below:

Variable                  Statistics                 

Age

     White                 N                 4

                               Mean           45

                               Median        43 (42 - 45)

     Black                 N                  4

                               Mean           44 

                               Median        40 (39 - 45)

Cost

    2001                  N                  3

                              Mean           90

                              Median        120 (100 -200)

   2002                   ETC.

Thank you.

 


 

Emma8
Quartz | Level 8

Thank you. But this isn’t what I want. I will use proc summary or proc means, but I want to know the sas codeabout looping over multiple dataset and save the results and report as one table report.

Reeza
Super User

Given what you've posted I don't think that's possible because your variables differ in too many respects.

Here's an example on how to create a table of charateristics for a single data set.
https://gist.github.com/statgeek/2f27939fd72d1dd7d8c8669cd39d7e67

And here's a tutorial on looping over macro variables:
https://gist.github.com/statgeek/9603186
https://gist.github.com/statgeek/1a8e008ecc2fe47e03c3d0022c361e78

And one on creating a macro:
https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

To combine data sets together use PROC APPEND.

Tom
Super User Tom
Super User

@Emma8 wrote:

Thank you. But this isn’t what I want. I will use proc summary or proc means, but I want to know the sas codeabout looping over multiple dataset and save the results and report as one table report.


You haven't described a problem that would benefit from any looping.  You want to calculate different statistics from different tables.  So do that.  You might find it useful to put the results into a dataset that will make it easy to produce the report you show.  Why not follow the model shown in this classic paper:  https://www.lexjansen.com/pharmasug/2010/TT/TT05.pdf

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 905 views
  • 1 like
  • 4 in conversation