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

problem.png

 From the table above, I would like to count number of successful and unsuccessful (failed and canceled state) kickstarter campaigns by main category.

I need to have table like this:

main_category | number_of_successful_campaigns | number_of_unsuccessful_campaigns

          x             |                              x                          |                             x

          y             |                              x                          |                             x

I do not know how should I even start.. 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16

1) Next time share some useful test data...

 

2) try this:

data have;
input id main_category $ state $;
cards;
1 X successful
2 Y successful
3 X failed
4 Y failed
5 X failed
6 X failed
7 Y successful
8 Y successful
;
run;
proc print;
run;

proc tabulate data = have out = want;
  class main_category state;
  table main_category, state*N;
run;

proc transpose data = want out = want(drop=_name_) prefix=number_of_ suffix=_campaigns;
  by main_category;
  id state;
  var N;
run;

proc print;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Amethyst | Level 16

1) Next time share some useful test data...

 

2) try this:

data have;
input id main_category $ state $;
cards;
1 X successful
2 Y successful
3 X failed
4 Y failed
5 X failed
6 X failed
7 Y successful
8 Y successful
;
run;
proc print;
run;

proc tabulate data = have out = want;
  class main_category state;
  table main_category, state*N;
run;

proc transpose data = want out = want(drop=_name_) prefix=number_of_ suffix=_campaigns;
  by main_category;
  id state;
  var N;
run;

proc print;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



moteku
Fluorite | Level 6

It works but now i have to understand PROC STATEMENTS you have used. Thanks. (I will remember to share data 😇)

yabwon
Amethyst | Level 16

1) Proc tabulate works as Excel's Pivot. it is just to aggregate data, you could use Proc SQL, for that job too.

2) Proc transpose is just for "reshaping" dataset.

 

B-)

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26
proc freq data=have;
     tables main_category*state;
run;

If you want to combine failed and cancelled, you can do that with custom formats, or in a DATA step.

 

In the future, please provide example data in a usable form, as a SAS data step (instructions). Data in a screen capture is not usable.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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