BookmarkSubscribeRSS Feed
div44
Calcite | Level 5

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

7 REPLIES 7
ballardw
Super User

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.

Reeza
Super User

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


 

sasuser123123
Quartz | Level 8
How to get sum of a variable..by group.it means I've Male and female in one variable like 'sex' and values in another variable like 'aval' so I want the result like

Gender
--------------
F. M
---------------
Aval. Aval
-------------------
Sum. Sum
--------------------
sasuser123123
Quartz | Level 8
Sorry I've mentioned Gender instead of sex
Patrick
Opal | Level 21

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.

sasuser123123
Quartz | Level 8

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..

 

 

 

 

Reeza
Super User
You should start your own question, not on a thread that's a year old.

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!

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.

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
  • 7 replies
  • 11285 views
  • 0 likes
  • 5 in conversation