Help using Base SAS procedures

What procedure would I use to create a two row table?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

What procedure would I use to create a two row table?

DATA _NULL_;

INPUT HOUR VALUE;

CARDS;

0     20

1     43

2     55

3     41

4     50

5     65

6     42

7     41

8     67

9     71

10     77

11     83

12     51

13     66

14     74

15     85

16     72

17     59

18     52

19     46

20     83

21     92

22     77

23     40

;

RUN;

What procedure would produce the following table?

Hour01234567891011121314151617181920212223
Value204355415065414267717783516674857259524683927740

Accepted Solutions
Solution
‎01-22-2013 07:09 PM
SAS Super FREQ
Posts: 8,868

Re: What procedure would I use to create a two row table?

Ah, I see what you want. It always helps to have the specs. Then, I think that PROC TABULATE would be better than PROC REPORT. Given the same data as above for 12 hours, use TABULATE with VALUE and VALUE2 in the row dimension and then HOUR in the column dimension.

cynthia

 

ods listing close;

ods html file='c:\temp\two_val_tab_across.html';

proc tabulate data=hours f=comma6.0;

  title 'Tabulate Example';

  class hour;

  var value value2;

  table value='Value' value2='Value2',

        hour / row=float;

  keylabel sum=' ';

run;

ods html close;

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: What procedure would I use to create a two row table?

using proc transpose; you need a name for your dataset, _null_ does not work here.

Super User
Posts: 5,516

Re: What procedure would I use to create a two row table?

Jeff,

It depends on what you mean by "table".  If you mean "data set", then Linlin is exactly right.  If you mean "report", here's something that comes close:

data have;

   input hour value;

   obsno = _n_;

cards;

...

;

proc tabulate data=have;

   class obsno;

   var hour value;

   tables obsno='Observation Number' * sum=' ' * f=5.,
             hour value;

run;

I would guess you can get PROC REPORT to do this without creating OBSNO, but I'm not as familiar with it.

Good luck.

Super User
Posts: 5,516

Re: What procedure would I use to create a two row table?

Posted in reply to Astounding

Sorry, I switched the rows and columns,  The TABLES statement should read:

tables hour value,

          obsno='Observation Number' * sum=' ' * f=5.;

Ooops.

Super User
Posts: 11,343

Re: What procedure would I use to create a two row table?

Posted in reply to Astounding

Don't need the OBSNO 

proc tabulate data =<dataset name>;

class hour;

var value;

table value,

hour=''*max=''*f=f5.0/box='Hour';

run;


Valued Guide
Posts: 634

Re: What procedure would I use to create a two row table?

Here are a couple of REPORT step variations on your table.

title1 'Value for Each Hour';
proc report data=have nowd;
column ('Hour' hour),value;
define hour / across ' ';
define value / analysis ' ';
run;

proc report data=have nowd;
column label ('Hour' hour) ,value;
define label / computed ' ';
define hour / across ' ';
define value / analysis ' ';
compute label / char length=6;
   label='Value';
endcomp;
run;

Frequent Contributor
Posts: 75

Re: What procedure would I use to create a two row table?

Art,

How would I add multiple rows of variables to the table? Using your first example (which works great, thank you!):

title1 'Value for Each Hour';

proc report data=have nowd;

column('Hour' hour),value1, value2;

define hour / across ' ';

define value1 / analysis ' ';

define value2 / analysis ' ';

run;

I've tried several diffrent ways and read up on the PROC REPORT procedure but I keep getting the same error every time:

ERROR:  THERE IS MORE THAN ONE ANALYSIS USAGE ASSOCIATED WITH THE COLUMN DEFINED BY THE FOLLOWING ELEMENTS.

I've tried using DISPLAY and defining all the variables ACROSS but cannot get it.

Thanks!
Jeff

SAS Super FREQ
Posts: 8,868

Re: What procedure would I use to create a two row table?

Hi:

  Using another comma in your COLUMN statement is probably NOT what you want to do.  I would not think that you would want to nest value2 under value1 (or value) under each hour.

  That is the cause of the error message that you are getting. Try the alternate syntax shown below (building on Art's example, but only with 12 hours)

cynthia

DATA hours;
INPUT HOUR VALUE value2;
CARDS;
0     20  22
1     43  44
2     55  56
3     41  45
4     50  55
5     65  66
6     42  44
7     41  43
8     67  68
9     71  77
10    77  78
11    83  88
12    51  55
;
RUN;

ods listing close;
ods html file='c:\temp\two_val_under_across.html';
 
title1 'Value for Each Hour';
proc report data=hours nowd;
column ('Hour' hour),(value value2);
define hour / across ' ';
define value / analysis 'Value';
define value2 / analysis 'Value2';
run;

      

proc report data=hours nowd;
column label ('Hour' hour) ,(value value2);
define label / computed ' ';
define hour / across ' ';
define value / analysis 'Value';
define value2 / analysis 'Value2';
compute label / char length=6;
   label='Value';
endcomp;
run;
ods html close;

Frequent Contributor
Posts: 75

Re: What procedure would I use to create a two row table?

Posted in reply to Cynthia_sas

Cynthia,

Thanks for the response. I tried you code and it got me closer to my goal! What I'm trying to accomplish is a simple table of variables by hour:

Hour          0       1       2       3      4...

Value1     20     43     55     41     50

Value2     22     44     56     45     55            

I could have up to four variables per table I want to build. I've tried PROC TRANSPOSE but I can't get the labels correct.

Jeff

Solution
‎01-22-2013 07:09 PM
SAS Super FREQ
Posts: 8,868

Re: What procedure would I use to create a two row table?

Ah, I see what you want. It always helps to have the specs. Then, I think that PROC TABULATE would be better than PROC REPORT. Given the same data as above for 12 hours, use TABULATE with VALUE and VALUE2 in the row dimension and then HOUR in the column dimension.

cynthia

 

ods listing close;

ods html file='c:\temp\two_val_tab_across.html';

proc tabulate data=hours f=comma6.0;

  title 'Tabulate Example';

  class hour;

  var value value2;

  table value='Value' value2='Value2',

        hour / row=float;

  keylabel sum=' ';

run;

ods html close;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 291 views
  • 1 like
  • 6 in conversation