BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10
Thank you Tom, but still "0" remains out. I also need to count (or sum) when all cat* have "0" to get 125, 33, 44. This output seems to disappear but I need to show numbers when no one has "1" in DB1
Tom
Super User Tom
Super User

@NewUsrStat wrote:
Thank you Tom, but still "0" remains out. I also need to count (or sum) when all cat* have "0" to get 125, 33, 44. This output seems to disappear but I need to show numbers when no one has "1" in DB1

I have no idea what that means.

Please create a small precise example of input and the results you want.  Explain in detail how you get that results from that input.  Spell out the STORY.  What do the CAT1 to CAT5 variables represent? What do the other two variables represent?  What to the observations in the input represent?  What do the observations in the output represent? What do the variables in the output represent?

 

Are you asking to create variables other than the 5 that exist in the data?  How do you know how many variables there could be? 

NewUsrStat
Lapis Lazuli | Level 10
So, regarding CAT =0 I mean just to add the frequencies when all cat*(s) in DB1 are 0 (no "1" index). This means to report 125, 33 and 44 relative to place 1, 2 and 3 respectively in the output you provided.
Ksharp
Super User
data DB1;
input cat1 cat2 cat3 cat4 cat5 place value;
cards;
0 0 0 0 0 1 125
0 0 0 0 0 2 33
0 0 0 0 0 3 44
0 0 1 0 0 1 2
0 0 1 0 0 2 .
0 0 1 0 0 3 1
0 1 0 0 0 1 .
0 1 0 0 0 2 .
0 1 0 0 0 3 .
0 1 0 1 0 1 65
0 1 0 1 0 2 36
0 1 0 1 0 3 43
0 1 1 0 0 1 .
0 1 1 0 0 2 .
0 1 1 1 0 1 4
0 1 1 1 0 2 2
1 0 0 0 0 1 164
1 0 0 0 0 2 516
1 0 0 0 0 3 619
1 0 1 0 0 1 5
1 0 1 0 0 2 1
1 0 1 0 0 3 2
;

proc sql;
create table want as
select 0 as cat,place,sum(value) as value from DB1 where sum(cat1,cat2,cat3,cat4,cat5)=0 group by place
union
select 1,place,sum(cat1*value) from DB1 group by place
union
select 2,place,sum(cat2*value) from DB1 group by place
union
select 3,place,sum(cat3*value) from DB1 group by place
union
select 4,place,sum(cat4*value) from DB1 group by place
union
select 5,place,sum(cat5*value) from DB1 group by place
;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 18 replies
  • 4706 views
  • 1 like
  • 4 in conversation