Help using Base SAS procedures

proc tabulate - columns with and without format

Reply
Occasional Contributor
Posts: 14

proc tabulate - columns with and without format

Hello,

I am writing a proc tabulate procedure. I need the same column two times. First without format then with format.

for example:
/*
proc tabulate data= Mydata missing order=data;

format var1 $var1form.;
format var2 $var2form.;

class year var1 var2 ;
var analyse;

table (var2='' * (var1='' all='Total') ), (year='' * analyse=''* {style=data_...etc ) *sum='';


by comp;
run;
*/


I need code of var1 and then text of var1 same for var2.

thanks
SAS Super FREQ
Posts: 8,743

Re: proc tabulate - columns with and without format

Hi:
In your question, you say that you need "the same column two times". However, in your code, you only show the use of VAR1 and VAR2 one time each in the TABLE statement. For example, given this output table from TABULATE for 1 value of COMP:
[pre]
comp=CANADA

+------------------------------------------------+
| | 1993 | 1994 |
+----------------------+------------+------------+
|EAST |FURNITURE | 26950.00| 24370.00|
| +-----------+------------+------------+
| |OFFICE | 37180.00| 38985.00|
| +-----------+------------+------------+
| |Total | 64130.00| 63355.00|
+----------+-----------+------------+------------+
|WEST |FURNITURE | 21614.00| 24930.00|
| +-----------+------------+------------+
| |OFFICE | 35276.00| 37685.00|
| +-----------+------------+------------+
| |Total | 56890.00| 62615.00|
+------------------------------------------------+
[/pre]

Let's assume that EAST/WEST are values for VAR2 and that FURNITURE/OFFICE are values for VAR1. How do you envision using "the same column two times", given the above example????? Since you did not show your data, your desired output or your formats, it is hard to imagine what you want.

If you want to post output or sample data or program code to the forum, in order to protect > and < symbols, preserve code and output indention and to otherwise learn how to post special symbols to the forum, refer to this previous forum posting. It talks about the LT and GT symbols and also discusses how to emphasize code and how to surround code snippets and output results with [pre] and [/pre]
http://support.sas.com/forums/thread.jspa?messageID=27609毙

cynthia

The code that produced the above output is here:
[pre]
data mydata;
set sashelp.prdsale;
where country in ('CANADA', 'GERMANY');
comp = country;
var1 = prodtype;
var2 = region;
analyse = actual;
run;

options nocenter;
proc tabulate data= Mydata missing order=data
formchar='|-+-+++++-+';

class year var1 var2 ;
var analyse;

table (var2='' * (var1='' all='Total') ),
(year='' * analyse=''*sum='');
by comp;
run;
[/pre]
Occasional Contributor
Posts: 14

Re: proc tabulate - columns with and without format

lets look at your example. Lets see we want to remove East from the left column, and put east as total. How do u do that?

I want it this way:



Furniture
Office
Total for East
Furniture
Office
Total for West


with a column per year on the right side of course. I couldnt right it properly. but I hope u understand how I want it.
Message was edited by: nidhi123 Message was edited by: nidhi123
Super User
Posts: 10,516

Re: proc tabulate - columns with and without format

Depending on what you mean per Cynthia's questions, I have had occasion to want both a code and text at the same time. My approach has been, in the steps that create the input data set, to create a new text variable that is the concatenation of the code and the text. Pick the order to concatenate depending on how you want the sort order in the tables.
Occasional Contributor
Posts: 14

Re: proc tabulate - columns with and without format

Thanks for ur answers cynthia and ballardw.

I think my solution is in ur tip ballardw. I will try this, and get back to u guys.. thanks again.
Ask a Question
Discussion stats
  • 4 replies
  • 96 views
  • 0 likes
  • 3 in conversation