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

I have a big database, with the variables: leaf, lgd, in_default.

 

I need a table of frequencies that give the average lgd per sheet na in_default.

 

And also the total percentage of dissipation per sheet.

 

I need it, for example:

 

LEAFIN_DEFAULT=0IN_DEFAULT=0ALL IN_DEFAULTPERCENTMEAN(LGD) 
120222%0,33 
212333%0,25 
322445%0,325 
ALL549   

 

DATABASE I HAVE:

LEAFLGDIN_DEFAULT
10,150
20,251
30,351
30,230
20,271
30,311
30,410
20,220
10,51

0

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Have you tried PROC TABULATE?

 

data have;
infile cards dsd truncover;
input LEAF	LGD	IN_DEFAULT;
cards;
1,	0.15,	0
2,	0.25,	1
3,	0.35,	1
3,	0.23,	0
2,	0.27,	1
3,	0.31,	1
3,	0.41,	0
2,	0.22,	0
1,	0.51,	0
;;;;

proc tabulate data=have;
class leaf in_default;
var LGD;
table (leaf all), (in_default All)*N PCTN LGD*Mean;
run;

@Thalitacosta wrote:

I have a big database, with the variables: leaf, lgd, in_default.

 

I need a table of frequencies that give the average lgd per sheet na in_default.

 

And also the total percentage of dissipation per sheet.

 

I need it, for example:

 

LEAF IN_DEFAULT=0 IN_DEFAULT=0 ALL IN_DEFAULT PERCENT MEAN(LGD)  
1 2 0 2 22% 0,33  
2 1 2 3 33% 0,25  
3 2 2 4 45% 0,325  
ALL 5 4 9      

 

DATABASE I HAVE:

LEAF LGD IN_DEFAULT
1 0,15 0
2 0,25 1
3 0,35 1
3 0,23 0
2 0,27 1
3 0,31 1
3 0,41 0
2 0,22 0
1 0,51

0


 

View solution in original post

3 REPLIES 3
Reeza
Super User

Have you tried PROC TABULATE?

 

data have;
infile cards dsd truncover;
input LEAF	LGD	IN_DEFAULT;
cards;
1,	0.15,	0
2,	0.25,	1
3,	0.35,	1
3,	0.23,	0
2,	0.27,	1
3,	0.31,	1
3,	0.41,	0
2,	0.22,	0
1,	0.51,	0
;;;;

proc tabulate data=have;
class leaf in_default;
var LGD;
table (leaf all), (in_default All)*N PCTN LGD*Mean;
run;

@Thalitacosta wrote:

I have a big database, with the variables: leaf, lgd, in_default.

 

I need a table of frequencies that give the average lgd per sheet na in_default.

 

And also the total percentage of dissipation per sheet.

 

I need it, for example:

 

LEAF IN_DEFAULT=0 IN_DEFAULT=0 ALL IN_DEFAULT PERCENT MEAN(LGD)  
1 2 0 2 22% 0,33  
2 1 2 3 33% 0,25  
3 2 2 4 45% 0,325  
ALL 5 4 9      

 

DATABASE I HAVE:

LEAF LGD IN_DEFAULT
1 0,15 0
2 0,25 1
3 0,35 1
3 0,23 0
2 0,27 1
3 0,31 1
3 0,41 0
2 0,22 0
1 0,51

0


 

ballardw
Super User

@Thalitacosta wrote:

I have a big database, with the variables: leaf, lgd, in_default.

 

I need a table of frequencies that give the average lgd per sheet na in_default.

 

And also the total percentage of dissipation per sheet.

 

I need it, for example:

 

LEAF IN_DEFAULT=0 IN_DEFAULT=0 ALL IN_DEFAULT PERCENT MEAN(LGD)  
1 2 0 2 22% 0,33  
2 1 2 3 33% 0,25  
3 2 2 4 45% 0,325  
ALL 5 4 9      

 

DATABASE I HAVE:

LEAF LGD IN_DEFAULT
1 0,15 0
2 0,25 1
3 0,35 1
3 0,23 0
2 0,27 1
3 0,31 1
3 0,41 0
2 0,22 0
1 0,51

0


Please look very closely at your "need" table. You have two columns with the same heading "IN_DEFAULT=0" without telling us what the numeric value below either one comes from. Where does the value from "ALL IN_DEFAULT" come from? And for the Percent numerator and denominator come from: not just variables but the numbers that would generate those

Ksharp
Super User
data have;
infile cards dsd truncover;
input LEAF	LGD	IN_DEFAULT;
cards;
1,	0.15,	0
2,	0.25,	1
3,	0.35,	1
3,	0.23,	0
2,	0.27,	1
3,	0.31,	1
3,	0.41,	0
2,	0.22,	0
1,	0.51,	0
;;;;

proc sql;
create table want as
select put(leaf,best32. -l) as leaf,
 sum(IN_DEFAULT=0) as a label='IN_DEFAULT=0',sum(IN_DEFAULT=1) as b label='IN_DEFAULT=1',
 count(*) as n label='ALL IN_DEFAULT',
 calculated n/(select count(*) from have) as per format=percent8.2 label='PERCENT',
 mean(LGD) as mean label='MEAN(LGD)' format=commax12.2
 from have 
  group by leaf
union all
select 'ALL',sum(IN_DEFAULT=0),sum(IN_DEFAULT=1),count(*),.,. from have
;
quit;

proc print label noobs;run;

Ksharp_0-1628335544438.png

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1309 views
  • 2 likes
  • 4 in conversation