DATA Step, Macro, Functions and more

Tabulate

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

Tabulate

i want to use the tabulate procedure to display the average time for each flavor and culture combination. I am not able to get the average time for each. I have tried few steps... plz suggest how to tabulate to get desired results

 

Available data;

Obs    flavor       culture       time

1         blueberry L.acidophilus 1.25381
2         blueberry L.acidophilus 1.19350
3         plain        L.acidophilus 1.08703
4         plain         L.acidophilus 1.40896
5         plain         L.acidophilus 2.63547
6         plain         L.acidophilus 2.69992
7        strawberry L.acidophilus 3.01486
8       strawberry L.acidophilus 3.35383
9       strawberry L.acidophilus 3.71758

10     strawberry L.acidophilus 3.38742
11     vanilla         L.acidophilus 4.15288
12     vanilla         L.acidophilus 4.34319

13     vanilla         L.acidophilus 4.12448
14     blueberry    B.bifidum 1.02099
15    blueberry     B.bifidum 1.46241
16    blueberry     B.bifidum 0.78172
17    plain             B.bifidum 1.59875
18     plain            B.bifidum 1.72159
19    cherry          B.bifidum 2.38972
20    cherry          B.bifidum 2.27279
21    vanilla          B.bifidum 3.17874
22    vanilla         B.bifidum 3.06254
23    vanilla         B.bifidum 3.20867

 

proc tabulate data=combination;
class flavor culture;
table flavor culture;
run;


Accepted Solutions
Solution
‎10-31-2016 10:34 AM
Super User
Posts: 10,041

Re: Tabulate

Actually f8.3 is the same as 8.3 . you can use 8.3 too .

View solution in original post


All Replies
Super User
Posts: 10,041

Re: Tabulate

CODE NOT TESTED


proc tabulate data=combination;
class flavor culture;
var time;
table flavor*culture, time*mean ;
run;

Contributor
Posts: 34

Re: Tabulate

Thank you - I was not using the var statement... I thought table statement wld be enough -
Super User
Posts: 10,041

Re: Tabulate

Yeah. Same thing happened to me. Usually overlooked.
Contributor
Posts: 34

Re: Tabulate

Dear Ksharp,

 

The table i wanted to create was cross-tabulation of the flavor and culture - so I wanted to have the flavors in the rows of the table and separate columns for the two cultures. This would create both the mean and row headers.

The table created by the code below have only the statistic header for means.

 

Moreover, want also to control of the header labels -want to remove the summary statistic (mean)

                                                                                         and row variable headers from the table.

                                                                                         plus the answers to 3 decimal places. 

CAN YOU PLEASE GUIDE--

 

proc tabulate data=yogurt;

class flavor culture;

var time;

table flavor*culture, time*mean ;

run;

 

 

 

Super User
Posts: 10,041

Re: Tabulate


data have;
infile cards expandtabs truncover;
input Obs    flavor  : $20.     culture : $20.   time;
cards;
1         blueberry L.acidophilus 1.25381
2         blueberry L.acidophilus 1.19350
3         plain        L.acidophilus 1.08703
4         plain         L.acidophilus 1.40896
5         plain         L.acidophilus 2.63547
6         plain         L.acidophilus 2.69992
7        strawberry L.acidophilus 3.01486
8       strawberry L.acidophilus 3.35383
9       strawberry L.acidophilus 3.71758
10     strawberry L.acidophilus 3.38742
11     vanilla         L.acidophilus 4.15288
12     vanilla         L.acidophilus 4.34319
13     vanilla         L.acidophilus 4.12448
14     blueberry    B.bifidum 1.02099
15    blueberry     B.bifidum 1.46241
16    blueberry     B.bifidum 0.78172
17    plain             B.bifidum 1.59875
18     plain            B.bifidum 1.72159
19    cherry          B.bifidum 2.38972
20    cherry          B.bifidum 2.27279
21    vanilla          B.bifidum 3.17874
22    vanilla         B.bifidum 3.06254
23    vanilla         B.bifidum 3.20867
;
run;

proc tabulate data=have;
class flavor culture;
var time;
table flavor='',culture*time=''*mean=''*f=f8.3 ;
run;
 


Contributor
Posts: 34

Re: Tabulate

Thank you - now the code is exactly i was working on..I just wanted to know f=f8.3 - 8.3 i understood used for 3 decimal places.. But f=f is for format=flavour8.3?
Solution
‎10-31-2016 10:34 AM
Super User
Posts: 10,041

Re: Tabulate

Actually f8.3 is the same as 8.3 . you can use 8.3 too .
Contributor
Posts: 34

Re: Tabulate

Noted with thanks.
Super User
Posts: 11,343

Re: Tabulate

I tend to think of F8.3 as Fixed, 8 columns and 3 decimal places. I think that way because I've been involved with enough projects reading data with the F8.3 format where the decimals are IMPLIED and inserted at read. I also use the F habitually to make sure that I am using the intended format not z8.3 or something else.

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 396 views
  • 0 likes
  • 3 in conversation