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

Hello Everyone

 

Probably another simple question but I am stuck. 

 

I have a data set that looks something like the following:

idfabric colorlocationpricefiveormore
1bluestore  $   4.99no
2blackwarehouse $   6.00yes
3redwarehouse $   2.00no
4bluestore  $  10.00yes
5blackstore  $   7.50yes
6redwarehouse $  10.00yes
7bluestore  $   5.00yes
8blackwarehouse $   3.00no
9redstore  $   1.00no
10bluestore  $   5.00yes

What I am trying to tabulate the count of each color that are say $5.00 or more per location which I can do pretty easily but I need another column that is the percentage of the grand total of the color regardless of location.

 

Something like:

 Store Warehouse 
colorcount%count%
Blue375.000
Black133.3133.3
Red00133.3

 

 

 

I have done something like below but, obviously, it is not really giving me what I want.

 

PROC FORMAT;
picture pctf (round) other='09.9';
RUN;

 

proc tabulate
data = birth.lowbirthweight17;
class color location;
table county, location*(n=' ' pctn<color>*f=pctf.);
where fiveormore = 'Yes'; 
run;

 

I just can't quite figure out how to do it.  Any help would be greatly appreciated.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Here is some UNTESTED code for you, since we can't work from screen captures (if you want tested code, we'd need the actual data as a SAS data step). If you make a binary variable that has numeric values 0 and 1 (instead of character values yes and no) then the math becomes much simpler. You probably don't even need PROC SUMMARY here, you could probably do it all in PROC REPORT, but that's the way I do it.

 

data have2;
    set have(drop=fiveormore);
    above5=(price>=5);
run;
proc summary nway data=have2;
    class fabric_color location;
    var above5;
    output out=stats sum=count mean=percent;
run;
proc report data=stats;
    columns fabric_color location,(count percent);
    define fabric_color/group;
    define location/across;
    define count/sum;
    define percent/sum;
run;

 

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

What is the denominator of the percent? How do you get 75% for the blue/store combination?

--
Paige Miller
victhor
Fluorite | Level 6

In the table there are total of 4 units of blue. 

Reeza
Super User
But your table only counts 3??????
Where does the other 1 disappear to and why then?
Reeza
Super User
Assuming your data is just a sample and the results are not actually the numbers you expect this should answer your question:
https://documentation.sas.com/?docsetId=proc&docsetTarget=p0vdza4puzkcghn1j5xtqfb4sahr.htm&docsetVer...
PaigeMiller
Diamond | Level 26

Here is some UNTESTED code for you, since we can't work from screen captures (if you want tested code, we'd need the actual data as a SAS data step). If you make a binary variable that has numeric values 0 and 1 (instead of character values yes and no) then the math becomes much simpler. You probably don't even need PROC SUMMARY here, you could probably do it all in PROC REPORT, but that's the way I do it.

 

data have2;
    set have(drop=fiveormore);
    above5=(price>=5);
run;
proc summary nway data=have2;
    class fabric_color location;
    var above5;
    output out=stats sum=count mean=percent;
run;
proc report data=stats;
    columns fabric_color location,(count percent);
    define fabric_color/group;
    define location/across;
    define count/sum;
    define percent/sum;
run;

 

--
Paige Miller
victhor
Fluorite | Level 6

I will give that a try.  Thanks for your time and your assistance.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 1026 views
  • 1 like
  • 3 in conversation