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

Hi there,

I'm new to SAS and need to create many tables which are a cross tabulated format.

These outputs will then be exported and referenced by excel which will generate charts and conditional formats.

The trouble is that I don't seem to be able to name the output table with the proc tabulate - they all get called summary table1 etc.  When there will be so many tables, how can I then know which to export and save as what...

Suggestions?

I've tried multiple google searches and not returned much, as well as looked at these forums but not found this specific answer.  The questions to date are about naming the variables - not the table.

If there is documentation that directs on this, please could you tell me the name of the manuals to look at.

Cheers,

JJ

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ


Hi:

  It depends on your code and your destination how you will name the TABULATE output tables. Are you using OUT= to name the output data or are you using ODS? For me, this works to make one output file named KOALA.HTML and the other output file is named WOMBAT.HTML. Then the OUT= option in each step makes an output dataset from the TABULATE procedure.

Cynthia

     

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

proc tabulate data=sashelp.shoes out=work.table_koala;

where product contains 'Casual';

class region;

var sales inventory;

  table region all,

        sales*(sum mean) inventory*sum;

run;

ods html close;

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

proc tabulate data=sashelp.shoes out=work.table_wombat;

where product contains 'Casual';

class region;

var sales returns;

  table region all,

        sales*(sum mean) returns*sum;

run;

ods html close;

View solution in original post

4 REPLIES 4
Cynthia_sas
SAS Super FREQ


Hi:

  It depends on your code and your destination how you will name the TABULATE output tables. Are you using OUT= to name the output data or are you using ODS? For me, this works to make one output file named KOALA.HTML and the other output file is named WOMBAT.HTML. Then the OUT= option in each step makes an output dataset from the TABULATE procedure.

Cynthia

     

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

proc tabulate data=sashelp.shoes out=work.table_koala;

where product contains 'Casual';

class region;

var sales inventory;

  table region all,

        sales*(sum mean) inventory*sum;

run;

ods html close;

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

proc tabulate data=sashelp.shoes out=work.table_wombat;

where product contains 'Casual';

class region;

var sales returns;

  table region all,

        sales*(sum mean) returns*sum;

run;

ods html close;

jjoliver1981
Calcite | Level 5

Hi there,

Thank you this worked perfectly.

For 10 extra points ;-), using your example above, could you tell me if it's possible to set sales to be "cupcakes" before hand, and then have "cupcakes" in the code?

Reason for asking is that I have multiple iterations of this code, generating numerous tables to be analysed, and to set that variable in advance and have to only change it in one place would reduce risk of errors creeping in.

ballardw
Super User

One solution you'd be looking for is a simple macro variable. Note the changes in the code to use " instead of ' to allow resolution of the macro variable, the reference the variable has & and first . in &topic..html says that what follows is concatenated with the variable but since you want a dot as part of the file name you need a second one.

%let topic=wombat;

ods html file="c:\temp\&topic..html";

proc tabulate data=sashelp.shoes out=work.table_&topic;

where product contains 'Casual';

class region;

var sales returns;

  table region all,

        sales*(sum mean) returns*sum;

run;

ods html close;

Next step would be actual macro programming, parameters and fun.

Cynthia_sas
SAS Super FREQ

And, for the extra 10 points, here's a paper I wrote about Macro Basics for New SAS Users: https://support.sas.com/resources/papers/proceedings13/120-2013.pdf   It may help you get started.

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1427 views
  • 0 likes
  • 3 in conversation