Help using Base SAS procedures

Proc tabulate arranging tables

Reply
Occasional Contributor
Posts: 13

Proc tabulate arranging tables

Need help Im proctabulating two tables A and B from the same data source. When i do, the other table appears at the bottom. I want the two tables to be arranged next to each other like this ( just example)                                                  

Tablea     Table b

xxxx         xxxx     

xxxx         xxxx

xxxx         xxxx               

Thanks.

Respected Advisor
Posts: 4,920

Re: Proc tabulate arranging tables

Please show the code you tried so far. - PG

PG
Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

Ive used a code like this

Proc tabulate data = tablea

class  item1 item2;

var colour;

table item1 all, item2 All;

run;

Proc tabulate data = tableb

class desp1 desp2;

var colour;

table desp1 all, desp2 All;

run;

I just want output table to display side by side.

Thanks

Respected Advisor
Posts: 4,920

Re: Proc tabulate arranging tables

I get something half decent with option columns=2  :

option orientation=portrait nodate nonumber;

title;

ods rtf file="&sasforum.\Reports\tabulate 2 col.rtf" columns=2 style=journal;

proc tabulate data=sashelp.class format=6.1;

class sex age;

var height;

table sex, height*age*mean="";

run;

proc tabulate data=sashelp.class format=6.1;

class sex age;

var weight;

table sex, weight*age*mean="";

run;

ods rtf close;

PG

PG
Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

So no code in sas that can arrange the tables side by side before export?

Respected Advisor
Posts: 4,920

Re: Proc tabulate arranging tables

Export to what? Where?

PG
Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

To CSV

Respected Advisor
Posts: 4,920

Re: Proc tabulate arranging tables

As far as I know, CSV format supports data tables but not report tables (with multi-level column and row headings). Is it the OUT= dataset(s) you are after? - PG

PG
Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

Is it the OUT= dataset(s) you are after? - PG

that's correct sorry not CSV.



Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

Just looking to the out = than could arrange the tables next to each other. Not sure whre I will position   your code on my code.

Could you explain the bit below?

ods rtf file="&sasforum.\Reports\tabulate 2 col.rtf" columns=2 style=journal;


Thanks.

Respected Advisor
Posts: 4,920

Re: Proc tabulate arranging tables

The ODS RTF statement directs procedure printed output to a .rtf file (compatible with Word). FILE= names the file that will be created, STYLE=journal chooses a table layout style named journal (default is HTMLBLUE) and COLUMNS=2 requests two printed columns. - PG

PG
Occasional Contributor
Posts: 13

Re: Proc tabulate arranging tables

Hi PG

Thanks your method works

When I do the export, results show on a microsoft word document. is it possible to export on EXCEL in the same format so tables arranged to next to each other?

Thanks.

SAS Super FREQ
Posts: 8,864

Re: Proc tabulate arranging tables

Hi, when you do a "true" EXPORT, you are sending SAS data format to other data format (for example SAS data format exported to SPSS data format, or SAS data format exported to DBF data format or SAS data format to Excel data format) You do a true data-to-data export with PROC EXPORT or the SAS Libname engine. In that scenario, then your two separate tables (data tables from OUT=) would NOT be placed side by side.

  However, as shown by PGStats, when you move to a REPORT format, for some (but not all) destinations, you can get "side by side" REPORT tables (not data tables). As far as ODS CSV, there is no support of the COLUMNS=2 option. That option is only for RTF/PDF, which are paged destinations and have the controls to do multi-column REPORT documents.

  When you use ODS, you have several methods to create ASCII text REPORT files -- either CSV, HTML or XML -- that Excel knows how to open and render. Unless you post process the CSV output (such as suggested by Xia), ODS CSV does not support the COLUMN option. ODS HTML does not support the COLUMN option. There is an ODS Destination called ODS HTMLPANEL, that will produce columnar output -- but the output is meant to be opened in a browser. I believe that the other destinations -- like ODS TAGSETS.EXCELXP and the experimental ODS EXCEL will put each TABULATE output on a separate worksheet, not side-by-side.

  So, in the end, it remains to be seen whether you want a SAS data-to-Excel data output or a SAS output report-to-Excel report document output. You might be able to use the PROC EXPORT or Libname engine methods to write named ranges side-by-side -- but that generally means you have to create the named ranges first.

cynthia

Super User
Posts: 10,023

Re: Proc tabulate arranging tables

You can use Notepad++ to get this once you output these two table into a CSV file.

Open it by Notepad++ and Use ALT+mouse selection to copy the second table at the next of the first table .

Ask a Question
Discussion stats
  • 13 replies
  • 844 views
  • 3 likes
  • 4 in conversation