BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PTD_SAS
Obsidian | Level 7

I want to insert a comment line with different text each time the value of a group variable changes in Proc Report.

I tried to use if-then-else statements with the Compute After statement but no luck so far.

I attached a sample program which I hope shows what I want to achieve, it creates a simple output.

Any help with suggestions on how to do this would be appreciated!

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Hi,

you could try the below code

title;

proc report data=one nowd;

column class var1 var2;

define class / group;

define var1 / mean;

define var2 / mean;

compute after class;

    if class='A' then

    text= "  This is where I want different text according to value of A";

    else if class='B' then

    text= "  This is where I want different text according to value of B";

    else text= "  This is where I want different text according to value of C";

    line text $;

endcomp;

run;

quit;

Thanks,

Jagadish

Thanks,
Jag

View solution in original post

9 REPLIES 9
Jagadishkatam
Amethyst | Level 16

Hi,

you could try the below code

title;

proc report data=one nowd;

column class var1 var2;

define class / group;

define var1 / mean;

define var2 / mean;

compute after class;

    if class='A' then

    text= "  This is where I want different text according to value of A";

    else if class='B' then

    text= "  This is where I want different text according to value of B";

    else text= "  This is where I want different text according to value of C";

    line text $;

endcomp;

run;

quit;

Thanks,

Jagadish

Thanks,
Jag
PTD_SAS
Obsidian | Level 7

Thanks a lot Jagadish, it worked fine!

Regards,

Fethon

ArtC
Rhodochrosite | Level 12

Notice that Jagadish has conditionally specified the TEXT value.  In a compute block you cannot conditionally execute LINE statements (this is unlike the DATA step where you can conditionally execute PUT statements.

PTD_SAS
Obsidian | Level 7

Yes, I found out that I couldn't use the Line statement conditionally when I got an error!

ArtC
Rhodochrosite | Level 12

The LINE statement simply cannot be conditionally executed.  This includes not only IF-THEN processing, but things like DO loops as well.

do i=1 to 10;

     line 'write text';

end;

will be processed as if we had written:

do i = 1 to 10;

end;

line 'write text';

LINE is executed only once!

Jagadishkatam
Amethyst | Level 16

Hi,

Just tried another method to get the comments inserted into the reports using proc formats

Here is the code

proc format;

    value $class "A"=" This is where I want different text according to value of A"

                 "B"=" This is where I want different text according to value of B"

                 "C"=" This is where I want different text according to value of C";

run;

title;

proc report data=one nowd;

column class var1 var2;

define class / group;

define var1 / mean;

define var2 / mean;

compute after class;

   line @1 class $class.;

endcomp;

run;

quit;

Thanks,

Jagadish

Thanks,
Jag
PTD_SAS
Obsidian | Level 7

Yes, this is a neat method as well.

Thanks,

Fethon

data_null__
Jade | Level 19

If you your condition includes "nothing" that can be simulated with $VARYING.

37763 - Conditionally print a LINE statement in PROC REPORT

proc report list nowd data=sashelp.class;
   define _all_ / display;
  
define name / order;
  
compute after name;
      length text $20;
     
if name in: ('C' 'P') then do;
         text = name;
         l=
20;
        
end;
     
else do;
         text=
' ';
         l=
0;
        
end;
     
line text $varying20. l;
      endcomp;

AlfredM       14       69    112.5
AliceF       13     56.5       84
BarbaraF       13     65.3       98
CarolF       14     62.8    102.5
Carol
HenryM       14     63.5    102.5
JamesM       12     57.3       83
JaneF       12     59.8     84.5
JanetF       15     62.5    112.5
JeffreyM       13     62.5       84
JohnM       12       59     99.5
JoyceF       11     51.3     50.5
JudyF       14     64.3       90
LouiseF       12     56.3       77
MaryF       15     66.5      112
PhilipM       16       72      150
Philip
RobertM       12     64.8      128
RonaldM       15       67      133
ThomasM       11     57.5       85
WilliamM       15     66.5      112

PTD_SAS
Obsidian | Level 7

Thanks, good tip!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 2113 views
  • 6 likes
  • 4 in conversation