BookmarkSubscribeRSS Feed
Eugenio211
Quartz | Level 8

Hi,

 

Can someone help me out in summarizing data? 

 

this is my proc step:

 

proc sql;

create table RevenueData as
select Loan_key,business_day
,revenue
,BadDebt
,BD_Date as COYearMonth format yymon.
,Rev_Date as RevYearMonth format yymon.
from TOtRevenueBD

;quit;

 

I want to summarize this so that the result can be:

LoanKey TotRevenue RevYearMonth TotBadDebt COYearMonth

 

I used proc summary however it's not giving me my desired result.

 

Thanks a lot.

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@Eugenio211 wrote:

Hi,

 

Can someone help me out in summarizing data? 

 

this is my proc step:

 

proc sql;

create table RevenueData as
select Loan_key,business_day
,revenue
,BadDebt
,BD_Date as COYearMonth format yymon.
,Rev_Date as RevYearMonth format yymon.
from TOtRevenueBD

;quit;

 

I want to summarize this so that the result can be:

LoanKey TotRevenue RevYearMonth TotBadDebt COYearMonth

 

I used proc summary however it's not giving me my desired result.

 

Thanks a lot.


Show us the code you used for PROC SUMMARY. Show us the results, and explain what is wrong.

 

Also, "summarize" is not a specific term ... do you want sums, or means, or percents, or something else?

--
Paige Miller
Eugenio211
Quartz | Level 8

here is my proc summary step:

 

proc summary data=RevenueData noprint nway missing;
class loan_key COYearMonth RevYearMonth;
var BadDebt revenue;
output out = RevData (drop = _type_ _freq_) sum=;
run;

 

It does not summarize the data, the result is in multiple rows. (see attached). you will notice the multiple loan_keys 

PaigeMiller
Diamond | Level 26

Sorry, I cannot download and open Microsoft Office documents. Please show a portion of the results in your reply, and explain what is wrong.

--
Paige Miller
Reeza
Super User

You get multiple rows because CLASS tells SAS to do summaries based on each level of the variable in the CLASS statement. 

 

If all you want is a total sum, you can use the following. If you want something else, show us the input and expected output and we can help you fill in the middle logic. 

 

proc summary data=RevenueData noprint nway missing;
var BadDebt revenue;
output out = RevData (drop = _type_ _freq_) sum=;
run;
ballardw
Super User

You should provide some starting data and what you expect the result to be along with any rules.

 

Providing undesired output without a very explicit description as to why it is undesired (such as the actual desired output) is relatively useless.

 

CLASS variables in Proc Summary (and means and many other SAS procedures) create groups of output. If you don't want each level of a variable to create a row of output then it likely doesn't belong on a Class statement. If you want to create a group of values from DATES such as calendar month for each year then apply an appropriate format in Proc Summary. Then the Formatted value will be used for the group. I suspect that is what you missed in your code:

 

format COYearMonth RevYearMonth yymon. ;

or similar.

 

 

 

Eugenio211
Quartz | Level 8

I want to sum the data.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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