BookmarkSubscribeRSS Feed
Cynthia_sas
SAS Super FREQ
Hi:
That $300. is the FORMATTED length which should be used to write the variable BEFORE_LINE to the output file.

The maximum length might conflict with LINESIZE if you were using the LISTING destination, however, since you are not using the LISTING destination, you can make that number bigger...or you can use the $VARYING. format in your COMPUTE block:
[pre]
lg=length(before_line);
line before_line $varying. lg;
[/pre]

The other issue you could be running into is the implied length for before_line -- which you could control with a LENGTH statement in your COMPUTE block.
[pre]
compute before _page_;
length before_line $500;
...more code...
[/pre]

The LENGTH statement controls the internal storage size of the variable BEFORE_LINE, while the format size in the LINE statement controls the displayed size of the variable.

cynthia
anandbillava
Fluorite | Level 6
Using startpage=no option in SAS 9.1.3 creates a weird problem when there is a single observation in a group and that starts in a new page. It does not prints the column headers rather it prints the group header twice. According to SAS tech support this issue is fixed in version 9.2
anandbillava
Fluorite | Level 6
Hello ,
In this program I wanted to print different variable which is other than the group variable inside the compute before block.
But its printing blank. But if I use the compute before varialbe then it prints without any problem. But printing different column or varirable inside the compute before using line is results in blank.

Original,
compute before region / style=Header{just=l font_weight=bold}; before_line = catx(' ','Region:',trim(region)); line before_line $100.; endcomp;
Instead of region I want to use some other variable like below..
compute before region / style=Header{just=l font_weight=bold}; before_line = catx(' ','Region:',trim(some_other_variable other than region)); line before_line $100.; endcomp;

Can somebody throw some light here ?
Thanks

Message was edited by: anandbillava Message was edited by: anandbillava
Cynthia_sas
SAS Super FREQ
Hi:

PROC REPORT is not like a DATA step program. The variable you want to show or use in the COMPUTE before block may not be available to PROC REPORT. Remember that PROC REPORT has a couple of rules that control behavior:

1) Left to Right rule: PROC REPORT builds each report row from left to right, as variables are listed on the COLUMN statement. So, for example, in the COLUMN statement below:
COLUMN REGION SUBSIDIARY PRODUCT SALES RETURNS;

There is no visibility of SUBSIDIARY or PRODUCT inside the COMPUTE block for REGION.

2) Every variable you use in a PROC REPORT step MUST be in the COLUMN statement or must be a temporary variable. So, for example, if you had this COLUMN statement:
COLUMN REGION PRODUCT SALES RETURNS;

Even if SUBSIDIARY was in the input dataset, if it is not even listed in the COLUMN statement, it will not be available to you for testing or using in a LINE statement.

I do not know which of these situations you are encountering, but I suspect that one of these rules is what is causing the blanks to appear. Refer to this paper for some ideas of how to accomplish different break processing.
http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf

cynthia
anandbillava
Fluorite | Level 6
I will go through that.

I have one more things in the above program can I print the group headers which is printed inside the compute block also in starting of each page. Now this is not prinitng when group spills into new page. Group prints only once.

I used by varialbe and other techniques but no luck yet. It prints group header when i use byval but it encounters different error. Accrodding to SAS this is a bug and its fixed in version 9.2.

The bug is when there is only one observation for a group and if it had to start from a new page then groups are printed twice.
Cynthia_sas
SAS Super FREQ
Hi:
For RTF and PDF, column headers should automatically repeat at the page break, except for the bugs noted. There is no way to "force" column headers anywhere except at a page break. Some folks workaround this by having a "fake" page break variable that's a group variable and then when that variable changes, you are using that variable as the page break variable and not the "automatic" page break behavior.

By "column headers" I mean the variable names or labels that appear above each column. I'm not exactly sure what you mean by "group headers". If, by group headers, you mean the headers that are written with a LINE statement in a COMPUTE BEFORE block, then the LOCATION for those headers will be determined by what kind of location is specified on the COMPUTE block. There is a big difference between:
COMPUTE BEFORE GROUP_VAR
and
COMPUTE BEFORE _PAGE_

As you noted, there is a bug in 9.1 with the specific situation you mention: one observation for a group, BY processing, etc, etc. (http://support.sas.com/kb/20/570.html) Trying to use COMPUTE BEFORE GROUP_VAR instead of COMPUTE BEFORE _PAGE_ will not give you a workaround. The only circumstance where this MIGHT be a workaround would be if you make your own "fake" page break variable and still this might not help if there was only one observation for a BY group.

At this point, I'd recommend opening a track with Tech Support or reopening your former track to see if they can help you with these modifications to your report.

cynthia
anandbillava
Fluorite | Level 6
I want to print a different variable which is formated with concatenation of different columns and it bas to be printed in the compute before column of region (group)..
How can I do it ?
anandbillava
Fluorite | Level 6
Any suggestion or prnting different varialbe in a compute before block.
Cynthia_sas
SAS Super FREQ
This really depends on your data. It is an impossible question to answer without seeing the data and the WHOLE program and understanding whether this is an attempt to workaround the BY group issue or not. And the code technique could also be impacted by the ODS destination you want.

You really might want to work with Tech Support on this question too. They can look at your data and advise you accordingly. I don't have a really great example, but this one shows the "left to right" rule with the LINE statement. Let's assume that I want to show TOTAL STORES for each region in my LINE statement that's going to be written before each region. There are several different ways to do that, but they all involve having ALL the the variables I want to reference listed -before- REGION in the COLUMN statement. Note that I am not attempting to duplicate your BY group and/or previous COMPUTE BEFORE _PAGE_ reports. The only point of this program is to illustrate how variables that I want to use in the COMPUTE BEFORE REGION need to appear -before- REGION in the COLUMN statement.

cynthia
[pre]

** 1) Use the sum of stores at the break before region. This only works;
** because STORES appears -before- REGION in the COMPUTE block;
ods pdf file='c:\temp\stores_sum1.pdf';

proc report data=sashelp.shoes nowd;
title '1) Use sum statistic for stores';
column stores region product subsidiary sales returns;
define stores / sum noprint;
define region /order;
define product / order;
define subsidiary / order;
define sales/ sum;
define returns / sum;
break after region / summarize page;
compute before region;
line 'Region: ' region $varying100.;
line 'Sum of Stores: ' stores.sum comma6.;
endcomp;
run;

ods _all_ close;

** Now, what if you do NOT want to have STORES on the report for some reason;
** or you want to make some adjustment in a data step program or ...;
** a) create a summary dataset from proc tabulate;
ods listing close; title;
proc tabulate data=sashelp.shoes out=work.totstores(rename=(stores_sum=totstores));
class region;
var stores;
tables region,stores ;
run;

** b) join total store number back with sashelp.shoes and make some new;
** variables that we will use in subsequent PROC REPORT steps.;
proc sql;
create table work.shoes as
select a.*, catx(' ','Using BRKVAR:',a.region,'-',put(b.totstores,comma6.)) as brkvar,
a.region as grpreg,
b.totstores
from sashelp.shoes as a,
work.totstores as b
where product in ('Boot', 'Sandal') and
a.region = b.region;
quit;

** c) show the newly created variables;
ods listing;
options ls=150;
proc print data=work.shoes (obs=150);
title 'Note how brkvar and grpreg and totstores are the same for every obs in a region';
title2 'We will use BRKVAR instead of REGION in the COMPUTE block';
title3 'and then we will use grpreg and totstores in the COMPUTE block';
var grpreg totstores brkvar region product subsidiary sales returns;
run;
title; footnote;
ods listing close;

** 2) Use the BRKVAR variable;
options nodate nonumber orientation=portrait;

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

proc report data=shoes nowd;
title '2) Use BRKVAR';
column brkvar region product subsidiary sales returns;
define brkvar / group noprint;
define region /order;
define product / order;
define subsidiary / order;
define sales/ sum;
define returns / sum;
break after region / summarize page;
compute before region;
line brkvar $varying100.;
endcomp;
run;

ods _all_ close;


** 3) Use GRPREG and TOTSTORES variables;
ods pdf file='c:\temp\usegrpreg3.pdf';

proc report data=shoes nowd;
title '3) Use GRPREG and TOTSTORES';
column grpreg totstores region product subsidiary sales returns;
define grpreg / group noprint;
define totstores / group noprint;
define region /order;
define product / order;
define subsidiary / order;
define sales/ sum;
define returns / sum;
break after region / summarize page;
compute before region;
line 'Region: ' grpreg $varying100.;
line 'Totstores: ' totstores comma6.;
endcomp;
run;

ods _all_ close;
title; footnote;
ods listing;


[/pre]
anandbillava
Fluorite | Level 6
I am posting again and again on this problem.
Now other thing that I am trying to change in my report is Adding group labels beofore the column headers. Now what is happening is Column headers are printed first and the with compute before block the group label is printed and then the column values are printed.

Is there a way to print report like this
Group1
column header1 column header2 ......................
value1 value2 ............

Group2
column header1 column header2 ......................
value1 value2 ............
Cynthia_sas
SAS Super FREQ
Hi:
If you go back to the very first programs I posted, there is a distinct location for COMPUTE BEFORE GROUP_VAR -- that is between the headers and above the first report row for the GROUP_VAR.
COMPUTE BEFORE _PAGE_ goes above the headers on each page. A simple COMPUTE before goes before the headers on the -first- page.

It may not be possible to get what you want using COMPUTE BEFORE GROUP_VAR. That's why I originally suggested COMPUTE BEFORE _PAGE_. The placement of the line in each type of COMPUTE block really cannot be changed. As I suggested earlier, since you have on-going issues, you might really be better served by opening a track with Tech Support.

cynthia

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 25 replies
  • 5861 views
  • 0 likes
  • 3 in conversation