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

Hello,

 

I have the following table:

IDDateRating
1Jan-14High
1Feb-14High
1Mar-14Low
2Jan-14Low
2Feb-14Low
3Jan-14High
3Feb-14High
4Jan-14Low
4Feb-14Low
4Mar-14High
4Apr-14High
5Jan-14Low

 

I am trying to create a count of the Ratings by Month to create the following table:

 Jan-14Feb-14Mar-14Apr-14Total
High22116
Low22105
Total442111

 

 

Any help would be greatly appreciated.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

4 REPLIES 4
Reeza
Super User

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.


 

ballardw
Super User

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;

 

thb
Fluorite | Level 6 thb
Fluorite | Level 6

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.

 

 

Reeza
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2153 views
  • 3 likes
  • 3 in conversation