Help using Base SAS procedures

PROC REPORT - Spliting lines with automatic length

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

PROC REPORT - Spliting lines with automatic length

Hello,

In the LISTING destination, does anyone knows how to separate blocks with a line without the need of specifying the length?

The following code only works for the first 2 pages, but for the last one, the line is too long.

proc report data=sashelp.cars nowd ls=100 headline nocenter;

where Make in ('Acura','Cadillac');

columns ("--" Make--Length);

define make / order id;

define model / order id width=20;

compute after make;

line @3 "-------------------------------------------------------------------------------------------";

endcomp;

compute after;

line @3 "my footnote which will contain the page number,";

line @3 "the output name and other useful information.";

endcomp;

run;

I need something that works automatically because this code is for a macro which should handle several situations.  Something like "--" in the column statement would be perfect, but as far as I know there is nothing similar in the compute statement.

This is the best I got, but it only adds lines under numeric variables, and adds empty space between columns.

proc report data=sashelp.cars nowd ls=100 headline nocenter width=100;

where Make in ('Acura','Cadillac');

columns ("--" Make--Length);

define make / order id;

define model / order id width=20;

break after make / ol;

compute after;

line @3 "my footnote which will contain the page number,";

line @3 "the output name and other useful information.";

endcomp;

run;

Thanks!!

Juan


Accepted Solutions
Solution
‎05-21-2014 01:39 PM
Respected Advisor
Posts: 3,799

Re: PROC REPORT - Spliting lines with automatic length

With destination LISTING you have the "luxury" of being able to post-process the file with relative ease.

This example assumes that the first line is the spanning header that is the full width of the output.  If you measure this line you can use that measurement to trim the LINE statement output that is too long.

For more complex output you will need alternative ways to find the optimal page with.

options number=0 center=1 date=0 ls=255;
filename FT74F001 temp;
ods listing file=FT74F001;
%let ls=100;
title1; footnote1;
proc report data=sashelp.cars ls=&ls nowd headline nocenter list;
  
where Make in ('Acura','Cadillac');
   columns ("--" Make--Length);
   define make / order id;
  
define model / order id width=20;
  
compute after make;
      line @3 %eval(&ls-3)*'-'; /*These line will be trimmed after we figure the correct length*/
  
endcomp;
  
compute after;
  
line @3 "my footnote which will contain the page number,";
  
line @3 "the output name and other useful information.";
  
endcomp;
  
run;
ods listing close;
ods listing;

/*data _null_;*/
/*   infile FT74F001;*/
/*   input;*/
/*   list;*/
/*   run;*/
Title 'Add title in this step';
Title2 'Add title2 in this step';

data _null_;
  
file print nofootnote ls=&ls;
   infile FT74F001 noprint;
  
input;
   np=first(_infile_) eq
'0C'x;
  
if _n_ eq 1 or np then do;
     
if np then do;
         _infile_ = substr(_infile_,
2);
         put _page_ @;
         end;
      l=length(_infile_);
     
put _infile_;
     
end;
  
else put _infile_ $varying256. l;
   retain l;
   run;

View solution in original post


All Replies
Valued Guide
Posts: 2,177

Re: PROC REPORT - Spliting lines with automatic length

LINE %SYSFUNC(  GETOPTION( LS))*'-' ;

Contributor
Posts: 43

Re: PROC REPORT - Spliting lines with automatic length

Thanks Peter,

I believe this only works if I use the whole line size for my report, which is not the case. Besides, this would set the same line length for all pages in the report. In my case, the width of the report is different among pages.

Any other idea? I starting to believe that there is no simple answer to this basic requirement.

Solution
‎05-21-2014 01:39 PM
Respected Advisor
Posts: 3,799

Re: PROC REPORT - Spliting lines with automatic length

With destination LISTING you have the "luxury" of being able to post-process the file with relative ease.

This example assumes that the first line is the spanning header that is the full width of the output.  If you measure this line you can use that measurement to trim the LINE statement output that is too long.

For more complex output you will need alternative ways to find the optimal page with.

options number=0 center=1 date=0 ls=255;
filename FT74F001 temp;
ods listing file=FT74F001;
%let ls=100;
title1; footnote1;
proc report data=sashelp.cars ls=&ls nowd headline nocenter list;
  
where Make in ('Acura','Cadillac');
   columns ("--" Make--Length);
   define make / order id;
  
define model / order id width=20;
  
compute after make;
      line @3 %eval(&ls-3)*'-'; /*These line will be trimmed after we figure the correct length*/
  
endcomp;
  
compute after;
  
line @3 "my footnote which will contain the page number,";
  
line @3 "the output name and other useful information.";
  
endcomp;
  
run;
ods listing close;
ods listing;

/*data _null_;*/
/*   infile FT74F001;*/
/*   input;*/
/*   list;*/
/*   run;*/
Title 'Add title in this step';
Title2 'Add title2 in this step';

data _null_;
  
file print nofootnote ls=&ls;
   infile FT74F001 noprint;
  
input;
   np=first(_infile_) eq
'0C'x;
  
if _n_ eq 1 or np then do;
     
if np then do;
         _infile_ = substr(_infile_,
2);
         put _page_ @;
         end;
      l=length(_infile_);
     
put _infile_;
     
end;
  
else put _infile_ $varying256. l;
   retain l;
   run;
Contributor
Posts: 43

Re: PROC REPORT - Spliting lines with automatic length

Posted in reply to data_null__

Trimming the output, that was very smart.

I am very impressed, thanks. I will try to adapt it to use in my macro.

Regards, Juan

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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