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
SAS Super FREQ

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
SAS Super FREQ

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1001 views
  • 0 likes
  • 3 in conversation