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 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
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??
Thank you.
I have many datasets but want to report just as one table.
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.
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.
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.
@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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.