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

Dear all,

I'm facing a product penetration problem.

I have a table t1

CustomerIDSavingAccountTermDepositLoan
aaaY
bbbYY
cccYY
dddY
eeeY

select t1.SavingAccount,count(Savingaccount) as sa, count(*) as allNo,

count(Savingaccount)/count(*) as penetration

from t1 group by savingaccount;

it will present

0    1      0%

4    4     100%

but what I want is

0    5      0%

4    5     80%

I want count(*) to calculate the original number,not the grouped number.

Can anyone give a hand?

Very thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

It looks like you need sub-query in SQL.

data have;
input (CustomerID     SavingAccount     TermDeposit     Loan) (: $40.);
cards;
aaa     . .     Y
bbb     Y     .     Y
ccc     Y     Y .     
ddd     Y . .          
eee     Y . .
;
run;
proc sql;
 create table want as
  select sum,(select count(*) from have) as total ,sum/calculated total as percent format=percent8.
   from (select count(SavingAccount) as sum from have group by SavingAccount);
quit;
   


Ksharp

View solution in original post

3 REPLIES 3
bbb_NG
Fluorite | Level 6

What I'm trying to ask further is

that when filter/group changed  how to change respectively,

what solution I present is that

when grouped by Savingaccount,

it will show as follows:

Y4
nill1
Total5

thus the penetration can be easily calculated.

Ksharp
Super User

It looks like you need sub-query in SQL.

data have;
input (CustomerID     SavingAccount     TermDeposit     Loan) (: $40.);
cards;
aaa     . .     Y
bbb     Y     .     Y
ccc     Y     Y .     
ddd     Y . .          
eee     Y . .
;
run;
proc sql;
 create table want as
  select sum,(select count(*) from have) as total ,sum/calculated total as percent format=percent8.
   from (select count(SavingAccount) as sum from have group by SavingAccount);
quit;
   


Ksharp

bbb_NG
Fluorite | Level 6

Ksharp,

Thanks for your  prompt and helpful reply.Very thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 3 replies
  • 1080 views
  • 0 likes
  • 2 in conversation