BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
PROC SQL;
   create table summary_ead_&p_yymmdd as
   select portfolio, product, ead,
       sum(ccf*rel_cnt)/sum(rel_cnt) as dcwccf
       avg(ccf) as dawccf
       count(*) as cnt
   from acct_list_final_&P_yymmdd
where ead in ('PHI','ALP')
   group by portfolio, product, ead,
quit;
 

cnt= count(*) - no of rows in dataset

but there is a clause 'where ead in ('PHI', 'ALP')'

so does count(*) include only those fulfilling where ead in ('PHI', 'ALP') or

all rows in dataset acct_list_final_&P_yymmdd regardless of where statement?

 

5 REPLIES 5
Astounding
PROC Star
Only rows with the right values for ead get counted. The same applies across the board. Only rows with the right values for ead get used to compute sums, means, counts.
HeatherNewton
Quartz | Level 8
So for each row cnt=1 or cnt=total no of row in whole table fulfiling the ead condition?
ballardw
Super User

@HeatherNewton wrote:
PROC SQL;
   create table summary_ead_&p_yymmdd as
   select portfolio, product, ead,
       sum(ccf*rel_cnt)/sum(rel_cnt) as dcwccf
       avg(ccf) as dawccf
       count(*) as cnt
   from acct_list_final_&P_yymmdd
where ead in ('PHI','ALP')
   group by portfolio, product, ead,
quit;
 

cnt= count(*) - no of rows in dataset

but there is a clause 'where ead in ('PHI', 'ALP')'

so does count(*) include only those fulfilling where ead in ('PHI', 'ALP') or

all rows in dataset acct_list_final_&P_yymmdd regardless of where statement?

 


If that is the actual code you submitted the comma after Ead in the Group by is going to cause problems. See this LOG from similar code:

109  proc sql;
110     select sex,age, mean(height) as mheight
111     from sashelp.class
112     group by sex,age,
113  quit;
ERROR: The following columns were not found in the contributing tables: quit.

So your output could have nothing because the comma before Quit isn't going to allow anything much to happen.

 

HeatherNewton
Quartz | Level 8

sorry it should be a semi-colon

assuming no code typo, what should count(*) for each row?

Kurt_Bremser
Super User

COUNT(*) counts all rows; if a GROUP BY is present, the summary functions (of which COUNT is one) will calculate for each group, otherwise for the whole dataset.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 795 views
  • 0 likes
  • 4 in conversation