Is there a way to do:
compute after gender but not after age / style={background=blue};
line ' ';
endcomp;
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;
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.
I don't quite understand your example. If you want a conditional line statement use $VARYING format as in the sample.
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;
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
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.
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;
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?
@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.
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;
@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;
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;
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.
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.
After moving them to the left the same error occurs.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.