BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
G_I_Jeff
Obsidian | Level 7

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
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

9 REPLIES 9
Linlin
Lapis Lazuli | Level 10

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

Astounding
PROC Star

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.

Astounding
PROC Star

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

tables hour value,

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

Ooops.

ballardw
Super User

Don't need the OBSNO 

proc tabulate data =<dataset name>;

class hour;

var value;

table value,

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

run;


ArtC
Rhodochrosite | Level 12

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;

G_I_Jeff
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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;

G_I_Jeff
Obsidian | Level 7

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

Cynthia_sas
SAS Super FREQ

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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