From: litonchen on
I have a problem about cross table. The following is a data example.

Type($) original_data(8.) modified_data(8.)
A 0.32 0.45
B 0.62 0.70
....
....

There are 3 columns, and original_data and modified_data are between
0~1. I want to produce the following cross table.

Type Value sum_of_original_data Sum_of_modified_data
A 0~0.5
A 0.5~1
B 0~0.5
B 0.5~1


How to produce the cross table??
From: Ya on
On Aug 9, 6:44 pm, "litonc...(a)gmail.com" <litonc...(a)gmail.com> wrote:
> I have a problem about cross table. The following is a data example.
>
> Type($)  original_data(8.)    modified_data(8.)
> A             0.32                   0.45
> B             0.62                   0.70
> ...
> ...
>
> There are 3 columns, and original_data and modified_data are between
> 0~1. I want to produce the following cross table.
>
> Type  Value  sum_of_original_data      Sum_of_modified_data
> A      0~0.5
> A      0.5~1
> B      0~0.5
> B      0.5~1
>
> How to produce the cross table??

Try this:

data have;
set have;
val=orig; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
vnm='Orig'; output;
val=modi; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
vnm='modi'; output;
run;

proc tabulate data=have;
class type rnge vnm;
var val;
table type=''*rnge='',vnm=''*val=''*sum='';
run;

HTH

Ya

From: litonchen on
On 8月10日, 上午11時12分, Ya <huang8...(a)gmail.com> wrote:
> On Aug 9, 6:44 pm, "litonc...(a)gmail.com" <litonc...(a)gmail.com> wrote:
>
>
>
>
>
> > I have a problem about cross table. The following is a data example.
>
> > Type($)  original_data(8.)    modified_data(8.)
> > A             0.32                   0.45
> > B             0.62                   0.70
> > ...
> > ...
>
> > There are 3 columns, and original_data and modified_data are between
> > 0~1. I want to produce the following cross table.
>
> > Type  Value  sum_of_original_data      Sum_of_modified_data
> > A      0~0.5
> > A      0.5~1
> > B      0~0.5
> > B      0.5~1
>
> > How to produce the cross table??
>
> Try this:
>
> data have;
>  set have;
> val=orig; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
> vnm='Orig'; output;
> val=modi; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
> vnm='modi'; output;
> run;
>
> proc tabulate data=have;
> class type rnge vnm;
> var val;
> table type=''*rnge='',vnm=''*val=''*sum='';
> run;
>
> HTH
>
> Ya

Hi, my trouble is I use a range columns(0~0.5,0.5~1) for original and
modified data. If I define both columns by range in text, I will get
4x2 cells in my tabulate.
------------------------------------------------------------------------------------------------------
| Original_Range | Modified_Range | Original_Sum | Modified_Sum |
------------------------------------------------------------------------------------------------------
| | 0~0.5
| | |
| 0~0.5 |
---------------------------------------------------------------------------
| | 0.5~1
| | |
-------------------------------------------------------------------------------------------------------
| | 0~0.5
| | |
| 0.5~1 |
---------------------------------------------------------------------------
| | 0.5~1
| | |
-------------------------------------------------------------------------------------------------------

In Fact, I want:
-----------------------------------------------------------------------------
| Range | Original_Sum | Modified_Sum |
----------------------------------------------------------------------------
| |
| |
| 0~0.5 |
| |
| |
| |
----------------------------------------------------------------------------
| |
| |
| 0.5~1 |
| |
| |
| |
----------------------------------------------------------------------------
From: Patrick on
data have;
infile datalines delimiter=' ' truncover;
input Type:$1. original_data:8. modified_data:8.;
datalines;
A 0.32 0.45
B 0.62 0.70
;
run;

data want(keep=type source value Cvalue);
set have;

source='original data';
value=original_data;
Cvalue=value;
output;

source='modified data';
value=modified_data;
Cvalue=value;
output;
run;

proc format;
value _range
0 - 0.5 = '0 - 0.5'
0.5 <- 1 = '>0.5 - 1'
;
run;

proc tabulate data=want;
class source Cvalue;
var value;
format Cvalue _range.;
table
Cvalue=' '
,source=' '*value=' '*sum=' '
/rts=15;
run;


From: Ya on
On Aug 10, 1:25 am, "litonc...(a)gmail.com" <litonc...(a)gmail.com> wrote:
> On 8月10日, 上午11時12分, Ya <huang8...(a)gmail.com> wrote:
>
>
>
>
>
> > On Aug 9, 6:44 pm, "litonc...(a)gmail.com" <litonc...(a)gmail.com> wrote:
>
> > > I have a problem about cross table. The following is a data example.
>
> > > Type($)  original_data(8.)    modified_data(8.)
> > > A             0.32                   0.45
> > > B             0.62                   0.70
> > > ...
> > > ...
>
> > > There are 3 columns, and original_data and modified_data are between
> > > 0~1. I want to produce the following cross table.
>
> > > Type  Value  sum_of_original_data      Sum_of_modified_data
> > > A      0~0.5
> > > A      0.5~1
> > > B      0~0.5
> > > B      0.5~1
>
> > > How to produce the cross table??
>
> > Try this:
>
> > data have;
> >  set have;
> > val=orig; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
> > vnm='Orig'; output;
> > val=modi; if 0<val<=0.5 then rnge='0~0.5'; else rnge='0.5~1';
> > vnm='modi'; output;
> > run;
>
> > proc tabulate data=have;
> > class type rnge vnm;
> > var val;
> > table type=''*rnge='',vnm=''*val=''*sum='';
> > run;
>
> > HTH
>
> > Ya
>
> Hi, my trouble is I use a range columns(0~0.5,0.5~1) for original and
> modified data. If I define both columns by range in text, I will get
> 4x2 cells in my tabulate.
> ---------------------------------------------------------------------------­---------------------------
> | Original_Range  |  Modified_Range | Original_Sum    | Modified_Sum |
> ---------------------------------------------------------------------------­---------------------------
> |                         |         0~0.5
> |                         |                      |
> |       0~0.5         |
> ---------------------------------------------------------------------------
> |                         |        0.5~1
> |                        |                       |
> ---------------------------------------------------------------------------­----------------------------
> |                         |         0~0.5
> |                         |                      |
> |       0.5~1         |
> ---------------------------------------------------------------------------
> |                         |        0.5~1
> |                        |                       |
> ---------------------------------------------------------------------------­----------------------------
>
> In Fact, I want:
> ---------------------------------------------------------------------------­--
> |       Range         | Original_Sum    | Modified_Sum |
> ---------------------------------------------------------------------------­-
> |                         |
> |                      |
> |       0~0.5          |
> |                      |
> |                         |
> |                      |
> ---------------------------------------------------------------------------­-
> |                         |
> |                      |
> |       0.5~1          |
> |                      |
> |                         |
> |                      |
> ---------------------------------------------------------------------------­-- Hide quoted text -
>
> - Show quoted text -

In that case, just drop the type:

proc tabulate data=have;
class /*type*/ rnge vnm;
var val;
table /*type=''*? rnge='',vnm=''*val=''*sum='';
run;