BookmarkSubscribeRSS Feed
SASSLICK001
Obsidian | Level 7

hello all

i am generating subtitles for a report and I'm using compute before _page_

line @1 test1 $20 test2 $20

i should not display test2 if it's empty  otherswIse I need to display, how can I achieve this?

3 REPLIES 3
Cynthia_sas
Diamond | Level 26

HI:

  You will have to use conditional logic in your COMPUTE block. But, you cannot execute LINE statements conditionally. (That is another argument against using the @20 pointer control in your LINE statement.) YOu will need to make a helper variable, a temporary variable such as PRTLINE in the example code below. Probably something like this:

COMPUTE ....;

  length prtline $100;
  if test2 = . then prtline = 'one thing';
  else if test2 gt . then prtline='another';

  line prtline $100.;
ENDCOMP:

cynthia

Ksharp
Super User

There is a way to conditional execute LINE statement via format $VARYING. ;

Here is an example :


proc report data=sashelp.class nowd;
column sex weight height;
define sex/order;
define weight/display;
define height/display;
compute weight;
if sex='F' then len=0;
  else len=20;
endcomp;
compute after sex;
line @1 'sex : ' sex $varying100. len;
endcomp;
run;

Xia Keshan

Cynthia_sas
Diamond | Level 26

Hi:

  I agree that you are controlling whether the LINE output displays or not based on the value for the LEN variable. But you are NOT, technically, conditionally executing the LINE statement (the LINE statement is not on the THEN or ELSE branch). What you are doing conditionally is setting the value for the LEN variable. The fact is that when LEN is 0, the LINE statement will suppress its output -- but the LINE statement is technically, still being executed because it has to discover the value of 0 for LEN, which has the impact of suppressing any display.

  Also, based on the example the OP posted in a different location, the value of TEST2 is on a single LINE with OTHER variable values -- the example LINE statement shows TEST1. So my take on the question was that the OP still wants the TEST1 part of the line to display -- not to be suppressed altogether. That is why I posted using a "helper" variable to hold 2 different strings instead of showing the way to suppress an entire line.

cynthia

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 3 replies
  • 1457 views
  • 0 likes
  • 3 in conversation