BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
I dont want to use any statistic to numeric variable which I am using in the var statement of proc tabulate, is it possible?
e.g
proc tabulate data=sample;
class x y z;
var w;
table x, y*(z,w);
run;
here I am getting sum of the values for the variable w, but I dont the sum. I just want to display the value of the variable W as it is.
please help me
1 REPLY 1
Cynthia_sas
SAS Super FREQ
Hi:
Look at and run the program below. Proc TABULATE is a summary procedure. If you have only one observation something uniquely identified by X, Y, Z values, then you should get the one row from TABULATE. However, Proc TABULATE's main purpose in life is to be a SUMMARY procedure and produce SUMMARY tables. So the default statistic associated with any numeric variable is the SUM statistic.

Depending on what you want to do, you may prefer output from PROC PRINT or PROC REPORT.

I'm not sure how you're getting numbers from TABULATE, when I run your program, I get the following error message:
[pre]
504 table x, y*(z,w);
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, ), *,
-, :, <, =, [, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_, {.
ERROR 200-322: The symbol is not recognized and will be ignored.
505 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE TABULATE used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


[/pre]

Both Proc PRINT and Proc REPORT will essentially provide you with a "detail" report, where every report row represents one observation in the data. For example, SASHELP.CLASS has 19 observations, one for each of 19 students. In my program, I create a data set called SAMPLE from SASHELP.CLASS and I create 21 observations -- an extra one for Alfred and an extra one for Janet. You can see, if you review the program output, that PROC PRINT and PROC REPORT show 2 rows for Alfred and 2 rows for Janet. But, PROC TABULATE creates just one report row for each of these students (and summarizes their values for W).

cynthia

[pre]
data sample;
set sashelp.class;

x = sex;
z = name;
if height gt 59 then y = 'XXX';
else y = 'YYY';
w = age;
output;

** create some extra obs to see diff between TAB and REPORT;
if name = 'Alfred' then output;
else if name = 'Janet' then output;
run;

proc sort data=sample out=sample;
by x y z w;
run;

ods html file='c:\temp\sample.html' style=sasweb;
proc print data=sample;
title 'Look at DATA';
title2 'Alfred and Janet each have 2 rows';
var x y z w;
run;

proc tabulate data=sample f=comma5.;
title 'Proc TABULATE';
title2 'With Tabulate, Alfred will have a value of 28 for W and Janet will have a value of 30';
class x y z;
var w;
table x, y*z ,w;
keylabel sum = ' ';
run;

proc report data=sample nowd;
title 'Proc REPORT';
title2 'With Proc REPORT, Alfred will have 2 rows of detail data and Janet will have 2 rows of detail data';
column x y z w;
define x / order;
define y / order;
define z / order;
define w / display;
break after x / page;
run;

proc tabulate data=sample;
title 'Original Program - gets error message';
class x y z;
var w;
table x, y*(z,w);
run;

ods html close;
[/pre]

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
  • 1 reply
  • 547 views
  • 0 likes
  • 2 in conversation