BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
TomKari
Onyx | Level 15

Hi, all

 

I have a fairly simple proc tabulate. Here's some code that emulates it (note the first data step is just to massage the data to somewhat closer to mine).

 

data pricedata;
	set sashelp.pricedata;

	if year(date)=1998;
	keep date productline productname sale price;
run;

title1 table of price data;

proc tabulate data=pricedata;
	class date productline productname;
	var sale price;
	table date, productname, productline * (sale*sum price*sum);
run;

It results in a table looks like this, with one page per month:

SASCom.jpg

I would like to use the value of date in some of the headings. On the page title, instead of "table of price data" I would like to see "table of price data for jan98" on the first page, feb98 on the second, etc. Again, instead of "Name of product line" and "Product Name", I would like to see "Name of product line for jan98" and "Product Name for jan98"

 

All assistance much appreciated!
   Tom

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I think you just need another variable and to suppress the display of label.

 

data pricedata;
	set sashelp.pricedata;
	if year(date)=1998;
	keep date: productline productname sale price;
   length date2 $64;
   date2 = catx(' ','Name of product line for', vvalue(date));
   run;
proc sort;
   by date;
   run;

title1 table of price data #byval1;

proc tabulate data=pricedata;
   by date;
	class date: productline productname;
	var sale price;
	table date, productname, date2=' '*productline=' '*(sale*sum='' price*sum='');
   run;

Capture.PNG

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

As I am not skilled in PROC TABULATE, I provide a PROC REPORT solution. Please note: I don't think there is a way to get the month into the name of variables in PROC REPORT or PROC TABULATE, and furthermore it is redundant, and at least in my opinion unnecessary to put the same information that is in the title elsewhere in the table. Nevertheless, using a title statement and BY statement like this ought to work in PROC TABULATE as well, but I am not able to provide that code.

 

proc sort data=sashelp.pricedata(where=(year(date)=1998)) out=pricedata;
    by date productline;
run;

options nobyline;
title "Table of Price Data for #byval1";
proc report data=pricedata;
    by date;
    columns productname (" " productline),(sale price);
    define productname/group;
    define productline/across " ";
    define sale/sum format=comma10.0;
    define price/sum format=dollar12.2;
run;

 

In addition, I think the productname column ought not to have the text "Product" (this is very redundant and takes up unnecessary space visually) in the product name, and the numbers sorted so that 2 follows 1 instead of 10 follows 1.

--
Paige Miller
Quentin
Super User

Agree with the Paige's BY statement approach, which also works fine for PROC TABULATE:

 

proc sort data=sashelp.pricedata(where=(year(date)=1998)) out=pricedata;
    by date productline;
run;

options nobyline ;
title "Table of Price Data for #byval1";
proc tabulate data=pricedata missing;
	class productline productname;
	var sale price;
	table productname, productline * (sale*sum price*sum);
  by date ;
run;
options byline ;
data_null__
Jade | Level 19

I think you just need another variable and to suppress the display of label.

 

data pricedata;
	set sashelp.pricedata;
	if year(date)=1998;
	keep date: productline productname sale price;
   length date2 $64;
   date2 = catx(' ','Name of product line for', vvalue(date));
   run;
proc sort;
   by date;
   run;

title1 table of price data #byval1;

proc tabulate data=pricedata;
   by date;
	class date: productline productname;
	var sale price;
	table date, productname, date2=' '*productline=' '*(sale*sum='' price*sum='');
   run;

Capture.PNG

TomKari
Onyx | Level 15

Thank you all! It was the "#byval1" feature that I was fishing for. I knew it existed, but I've never used it and I simply couldn't put together a search string that found it. All the other great code that you guys have provided is a bonus!

 

Tom

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 956 views
  • 1 like
  • 4 in conversation