Hello,
I have the following table:
| ID | Date | Rating |
| 1 | Jan-14 | High |
| 1 | Feb-14 | High |
| 1 | Mar-14 | Low |
| 2 | Jan-14 | Low |
| 2 | Feb-14 | Low |
| 3 | Jan-14 | High |
| 3 | Feb-14 | High |
| 4 | Jan-14 | Low |
| 4 | Feb-14 | Low |
| 4 | Mar-14 | High |
| 4 | Apr-14 | High |
| 5 | Jan-14 | Low |
I am trying to create a count of the Ratings by Month to create the following table:
| Jan-14 | Feb-14 | Mar-14 | Apr-14 | Total | |
| High | 2 | 2 | 1 | 1 | 6 |
| Low | 2 | 2 | 1 | 0 | 5 |
| Total | 4 | 4 | 2 | 1 | 11 |
Any help would be greatly appreciated.
Thank you in advance.
You can use ODS EXCEL to export output directly to a file.
ods excel file='C:\temp\demo.xlsx';
proc freq data=have;
table rating*date/ out=want;
run;
ods excel close;
This also creates a data set called WANT with the values you need. If you need it exactly as shown you can add a proc transpose to switch it to that format.
Have you tried PROC FREQ?
@thb wrote:
Hello,
I have the following table:
ID Date Rating 1 Jan-14 High 1 Feb-14 High 1 Mar-14 Low 2 Jan-14 Low 2 Feb-14 Low 3 Jan-14 High 3 Feb-14 High 4 Jan-14 Low 4 Feb-14 Low 4 Mar-14 High 4 Apr-14 High 5 Jan-14 Low
I am trying to create a count of the Ratings by Month to create the following table:
Jan-14 Feb-14 Mar-14 Apr-14 Total High 2 2 1 1 6 Low 2 2 1 0 5 Total 4 4 2 1 11
Any help would be greatly appreciated.
Thank you in advance.
Do you want a data set or a report?
On way for a quick report
Proc tabulate data=have;
class date rating;
table rating=' ' all='Total',
(date=' ' All='Total') *n;
run;
Hi Ballardfw,
Thank you for your response. While the report is exactly what I'm looking for, I need to create a table with it for exporting.
You can use ODS EXCEL to export output directly to a file.
ods excel file='C:\temp\demo.xlsx';
proc freq data=have;
table rating*date/ out=want;
run;
ods excel close;
This also creates a data set called WANT with the values you need. If you need it exactly as shown you can add a proc transpose to switch it to that format.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.