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

Is there a way to do:

compute after gender but not after age  / style={background=blue};

       line ' ';

 endcomp;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

This might be helpful but seems a bit clunky.

 

proc sort  data=sashelp.class out=class;	
	by sex age;
   run;
data report;
   set class;
   by sex age;
   lastsex = last.sex;
   lastage = last.age;
   run;
proc report nowd data=report list out=test;
   columns sex lastsex age lastage name height weight;
   define sex / order;
   define age / order;
   define lastsex / order noprint;
   define lastage / order noprint;
   define name / display;
   define height / display;
   define weight / display;
   compute after lastage / style={background=lightblue};
      x = ' ';
      if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;
      endcomp; 
	compute after sex / style={background=blue};		
		line ' ';
		endcomp;
	run;

Capture.PNG

View solution in original post

22 REPLIES 22
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, there maybe in report, but I prefer pre-arranging data in a datastep, som my suggestion would be to add a break var into your dataset, i.e. its always 0, except when you line, then break on that.

data_null__
Jade | Level 19

I don't quite understand your example.  If you want a conditional line statement use $VARYING format as in the sample.

http://support.sas.com/kb/37/763.html

DavidPhillips2
Rhodochrosite | Level 12

See screen shot.  What I’m trying to do is only produce one line when the blue line is created rather than both the blue line and the light blue line.


compute after gender / style={background=blue};
line ' ';
endcomp;

compute after age / style={background=lightblue};
line ' ';
endcomp;


two lines.png
Cynthia_sas
SAS Super FREQ

Which line do you want between Female and Male??? The light blue line or the dark blue line?

 

The technique described (to use $varying. is the correct technique to suppress a line statement. You CANNOT execute a LINE statement conditionally, but you can conditionally assign a value to a "helper" variable that specifies the length of the line. When the length of the line is 0, then PROC REPORT will suppress the line.

 

Please see this Tech Support note: http://support.sas.com/kb/37/763.html which outlines the basic technique (illustrated with writing out text). And this paper http://support.sas.com/resources/papers/proceedings11/246-2011.pdf has more examples and explanation on pages 12 and 13.

 

cynthia

DavidPhillips2
Rhodochrosite | Level 12

I want the last light blue line to not appear.  Currently playing with

 

if residency_desc = "Total" then do;                          

     call define(_col_, 'style', 'style=[background=lightblue]');

     line ' ';

end;

else do;                          

     call define(_col_, 'style', 'style=[background=blue]');

     line ' ';

end;

 

But this produces two blank lines.

data_null__
Jade | Level 19

This might be helpful but seems a bit clunky.

 

proc sort  data=sashelp.class out=class;	
	by sex age;
   run;
data report;
   set class;
   by sex age;
   lastsex = last.sex;
   lastage = last.age;
   run;
proc report nowd data=report list out=test;
   columns sex lastsex age lastage name height weight;
   define sex / order;
   define age / order;
   define lastsex / order noprint;
   define lastage / order noprint;
   define name / display;
   define height / display;
   define weight / display;
   compute after lastage / style={background=lightblue};
      x = ' ';
      if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;
      endcomp; 
	compute after sex / style={background=blue};		
		line ' ';
		endcomp;
	run;

Capture.PNG

DavidPhillips2
Rhodochrosite | Level 12
if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;

Could you explain what these two lines do?  They seem to matter why is lastage being set to 0?

data_null__
Jade | Level 19

@DavidPhillips2 wrote:
if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;

Could you explain what these two lines do?  They seem to matter why is lastage being set to 0?


Lastage is both the indicator of last obs for an age group and used as the length for X in $VARYING.  When LASTAGE is 0 it keeps the compute from printing a light blue line.  Otherwise there would be a line between each row.  When it is LASTSEX it is also LASTAGE but we want to suppress the printing of that line so set it (LASTAGE) to 0 and $VARYING prints nothing.

DavidPhillips2
Rhodochrosite | Level 12

When I run this with my dataset and a third column I run into:

 

NOTE: Variable lastsex is uninitialized.ERROR: An unknown, abnormal error has occurred. This step is being terminated.

 

It’s hard to replicate my scenario via a post.  Working on a simplification so I can post code and data.

 

This block is causing the error for me.

 

  compute after lastage / style={background=lightblue};
      x = ' ';
      if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;
      endcomp; 
data_null__
Jade | Level 19

@DavidPhillips2 wrote:

When I run this with my dataset and a third column I run into:

 

NOTE: Variable lastsex is uninitialized.ERROR: An unknown, abnormal error has occurred. This step is being terminated.

 

It’s hard to replicate my scenario via a post.  Working on a simplification so I can post code and data.

 

This block is causing the error for me.

 

  compute after lastage / style={background=lightblue};
      x = ' ';
      if lastsex eq 1 then lastage=0;
      line x $varying1. lastage;
      endcomp; 

 

 

You need to create "last" indicator variables for your data as I did in this step.  They also go in the column statement.

 

data report;
   set class;
   by sex age;
   lastsex = last.sex;
   lastage = last.age;
   run;
DavidPhillips2
Rhodochrosite | Level 12

This is a bit simplified.  Still simplifying and working on getting data for the post.

 

proc sort data=all;

       by gender residency eth;

run;

 

data all; set all;

        by gender residency eth;

        lastGender = last.gender;

        lastResidency = last.residency;

        lastEth = last.eth;

run;

 

proc report data=all;

               

      column (gender residency eth growthDeclineColumn perGrowthDeclineColumn lastGender lastResidency lastEth     academic_period_desc , n);

          

       define gender / group  '' order=data;

       define residency / group  '' order=data;

       define eth / group '' order=internal;

          

       define lastEth / order=data;

       define lastResidency / order=data;

       define lastGender / order=data;

 

       define growthDeclineColumn                      / group noprint '' order = data;

       define perGrowthDeclineColumn              / group noprint '' order = data;

       define academic_period_desc                / across ''

       define n                                   / analysis sum '' &tabulateFormatClause;

    

       compute eth;

            if eth=99  then call define(_row_,'style','style={font_weight=bold}');

       endcomp;

    

      compute n;

            if growthDeclineColumn = 1 then call &shortFormat;

            if perGrowthDeclineColumn = 1 then call define(_col_,'format','percent8.2');

       endcomp;

    

       compute after residency / style=[background=blue];

             x = ' ';

            if lastGender eq 1 then lastResidency =0;       

           line x $varying1. lastResidency;

     endcomp;

DavidPhillips2
Rhodochrosite | Level 12

if lastReport1 eq 1 or lastReport1 eq .  then lastReport2 =0; 

makes the proc report show without coloring.  Oddly proc print of dataset all displays lastReport1 with values.  I wonder if this has to do with the after statements.

data_null__
Jade | Level 19

You need to move the LAST indicator variables to the LEFT in the column statement.  Notice in my example they are not at the end.

DavidPhillips2
Rhodochrosite | Level 12

After moving them to the left the same error occurs.

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
  • 22 replies
  • 3658 views
  • 1 like
  • 4 in conversation