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
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;
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;
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.
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.