Proc Print option similar to Spanrows option in proc report

Reply
Occasional Contributor
Posts: 15

Proc Print option similar to Spanrows option in proc report

Hello!

Is there a proc print option similar to the spanrows option in proc report? I created a table using proc print and ods pdf, and when I run the code, it doesn't repeat a category value, even though some of the indicators related to that category are on the new page. Is there a way to repeat a value when the value breaks across pages? Thanks in advance!

Kelly

SAS Super FREQ
Posts: 8,866

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to kelly6984

Hi:

  SPANROWS is only available for PROC REPORT. It is not a valid option for PROC PRINT. However, PROC REPORT can generate a detail report (similar to what you get with PROC PRINT). You need to use the ORDER usage for at least some of your variables, so that SPANROWS effect will be aparent on your report (such as you get for TYPE and MAKE if you run the code below), then the other variables can be DISPLAY usage. You should see that "Sedan" repeats at the top of every page and when a MAKE splits across pages (such as Toyota), on my report, Toyota appears at the top of the page after the break, too.

cynthia

ods pdf file='c:\temp\spanrows.pdf';

 

proc report data=sashelp.cars nowd spanrows;

  where type = 'Sedan' and mpg_city ge 20;

  title 'PROC REPORT and SPANROWS';

  column type make model msrp mpg_city mpg_highway;

  define type / order;

  define make / order;

  define model / display;

  define msrp / display;

  define mpg_city / display;

  define mpg_highway / display;

run;

 

ods pdf close;

Occasional Contributor
Posts: 15

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to Cynthia_sas

Thanks so much! But, is there anything within proc print that works similarly to spanrows?

SAS Super FREQ
Posts: 8,866

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to kelly6984

  Sorry, there is nothing with PROC PRINT that is really similar to SPANROWS. Generally, when you reach the end of the road with PROC PRINT and what it can do, most folks transition over to PROC REPORT because it has several features that take it beyond what you can do with PROC PRINT. (Although I love PROC PRINT, PROC REPORT can do so much more..)

 

  But you didn't show your code, so I'm not sure what you mean when you say that PROC PRINT "doesn't repeat a category value, even though some of the indicators related to that category are on the new page". When I use PROC PRINT on SASHELP.CARS, I see the values for TYPE and MAKE on every row for report #1, and then for report #2, I see a separate page for every TYPE/MAKE combination. But, "Sedan" is repeated at the top of every page.

cynthia

ods pdf file='c:\temp\id_only.pdf' ;

proc print data=sashelp.cars;

  where type = 'Sedan' and mpg_city ge 20;

  title '1) Simple PROC PRINT and ID instead of OBS';

  ID type make;

  var model msrp mpg_city mpg_highway;

run;

ods pdf close;

   

proc sort data=sashelp.cars out=cars;

  by type make;

run;

 

ods pdf file='c:\temp\id_by.pdf';

proc print data=cars;

  where type = 'Sedan' and mpg_city ge 20;

  title '2) Simple PROC PRINT and ID with BY';

  by type make;

  ID type make;

  var model msrp mpg_city mpg_highway;

run;

ods pdf close;

Occasional Contributor
Posts: 15

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to Cynthia_sas

If you look at your report #2 pdf, Sedan and Chevrolet does repeat on the 2nd page, even when there are more Chevrolet models on the 2nd page. That's the problem I'm faced with...how do you get Sedan and Chevrolet to repeat on the 2nd page.

SAS Super FREQ
Posts: 8,866

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to kelly6984

In my report #2 (see attached), Sedan/Chevrolet is followed by Sedan/Chrysler (page 5 and 6)  and Chevies only take up 1 page (there are only 15 obs where TYPE=Sedan and Make=Chevrolet in all of SASHELP.CARS). Did you remove the WHERE clause from my code? I did have a filter on mpg_city -- which makes the number of rows even less than 15?  Or??? I ran my code in SAS 9.3 and opened the file with Acrobat Reader 9.

cynthia


report_2_pdf_id_by.png
Occasional Contributor
Posts: 15

Re: Proc Print option similar to Spanrows option in proc report

Posted in reply to Cynthia_sas

I do like your idea about transitioning to Proc Report. I think I may do that! Thanks a bunch!

Ask a Question
Discussion stats
  • 6 replies
  • 467 views
  • 0 likes
  • 2 in conversation