Hello,
I have a variable x which is a binary variable (may have missing values). A sum function in proc means would give me value of 60. (yes=60, no or missing=40).
When I use the sum function in proc tabulate with a class statement, I get the number of obs (n=100) instead of the sum (60).
Here is the code I am using:
proc tabulate data = have;
var x;
class y;
table x*sum, y;
run;
Any help would be appreciated.
Thanks
Show your output or provide the data used in the form of a data step, preferably both.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Your code works fine for me. You have some other issue.
If you run the following the results should be the following. I added in the Count/N so you can see the difference and the PROC MEANS to show that the results are correct.
y | |||
---|---|---|---|
0 | 1 | ||
x | Sum | 20.00 | 12.00 |
x | N | 56 | 44 |
data have;
call streaminit(12345);
do i=1 to 100;
x=rand('bernoulli', 0.4);
y=rand('bernoulli', 0.5);
output;
end;
run;
proc tabulate data=have;
var x;
class y;
table x*sum x*n, y;
run;
proc means data=have n sum nway;
var x;
class y;
run;
@div44 wrote:
Hello,
I have a variable x which is a binary variable (may have missing values). A sum function in proc means would give me value of 60. (yes=60, no or missing=40).
When I use the sum function in proc tabulate with a class statement, I get the number of obs (n=100) instead of the sum (60).
Here is the code I am using:
proc tabulate data = have;
var x;
class y;
table x*sum, y;
run;
Any help would be appreciated.
Thanks
As @Reeza demonstrated your code should work. If this is not the case then you need to post a SAS data step which creates sample data, your proc which creates the report with the "issue" using your sample data - and then explain us what result you want instead.
data is
sub sex site trt avisit paramcd aval
001 F USA palcebo week0 alt 9
002 F USA sudy_dr week0 ast 10
003 M USA palcebo week4 alt 11
004 F USA palcebo week4 ast 10
005 M ex-USA sudy_dr week0 alt 16
006 M USA palcebo week0 ast 11
007 F ex-USA sudy_dr week4 alt 13
008 M USA palcebo week0 ast 16
009 F ex-USA sudy_dr week0 alt 10
010 M USA palcebo week4 ast 17
I need Output like
Avisit
week0 week4
sex all sex all
F M F M
site
USA TRT
placebo 50 . 50 50 . 50
study_dr . 50 50 . 50 50
all 100 100 100 100 100 100
ex-USA TRT
placebo 25 50 75 25 50 75
study_dr 25 25 25 25
all 100 100 100 100 100 100
please find out the solution....using proc tabulate .....actually I've 24 observations but I took only 10..
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.