The message you are trying to access is permanently deleted.
delted
Depending on how your variables are calculated, you might run into numeric precision issues that cause differences where there should be none.
Use the round() function to remove any artifacts that hide far behind the decimal comma.
For better readability, I would also replace "not eq" with the simpler mnemonic "ne".
Thanks Kurt 🙂
However both the suggestions has no effect on the report !
COMPUTE AMTPRE;
IF round(AMTPRE,.02) ne round(AMTPRE_1096 ,.02)
THEN DO ;
call define (_col_,"style","style={background= orange}");
END;
ENDCOMP;
Hi:
How are AMTPRE and AMTPRE96 (and other variables) used on the report. By that I mean are you specifically listing them in a DEFINE statement with a usage of DISPLAY? Or are you taking the default usage of SUM?
What does your COLUMN statement look like? For example, you need to remember the "left to right" rule of PROC REPORT. PROC REPORT does not work like the DATA step. There is NO Program Data Vector. PROC REPORT can only "see" what has been placed on the report row, working from left to right.
Here is an example of what I mean:
proc report data=fakedata;
column var1 var2 var3 var4;
define var1 / display;
define var2 / display;
define var3 / sum;
define var4 / sum;
compute var1;
if var1 ne var2 then do;
call define (....);
end;
endcomp;
compute var4;
if var3.sum ne var4.sum then do;
call define (....);
end;
endcomp;
run;
The COMPUTE block for VAR1 is WRONG because of the left to right rule. At the point in time when PROC REPORT is writing VAR1 on the report, it has not yet written VAR2, so even though the comparison in the IF is correct for DISPLAY variables, the result will ALWAYS be false because at this point in time even if VAR1 has a value, VAR2 is missing on the report row because it hasn't been written yet. So the IF will ALWAYS be true.
As shown in the COMPUTE block for VAR4, you can test any item on the REPORT row, that is to the left of VAR4. So, although a COMPUTE block for VAR3 could NOT test VAR4, a COMPUTE block for VAR4 could test VAR3.
PROC REPORT ALWAYS moves from left to right, placing items on the report row one by one. So it is a timing and placement issue.
Then there are just a few other things to remember: for numeric variables that are NOT GROUP, ORDER or DISPLAY usage, you MUST use the construct: variable_name.statistic (as in VAR3.sum or VAR4.sum) and the syntax in the call define will need to be different. If you want to "touch" VAR3 in the COMPUTE block for VAR4, then the CALL DEFINE has to be like this:
compute var4;
if var3.sum ne var4.sum then do;
call define ('var3.sum','style','style={background=orange}');
end;
endcomp;
Notice how instead of _COL_, you need to use the item reference in quotes if you want to impact an item that is to the left of the item in the COMPUTE block.
cynthia
dekle
I Understand it works on Left to Right .. However if i want to compare my right with Left again , What i suppose to do ?
Pls suggest me the Changes
It seems to depend on the existence of a column. Computing a new one does the trick:
data test;
x1 = 1;
x2 = 2;
output;
x1 = 1;
x2 = 1;
output;
run;
proc report data=test;
column x1 x2 x3;
define x1 / display noprint;
define x2 / display;
compute x3;
if x1 ne x2
then call define(_col_,"style","style={background=orange}");
x3 = x1;
endcomp;
run;
Hi:
You can always "impact" x1 and x2 in the COMPUTE block for x3 because at the point in time when X3 is being placed on the report, PROC REPORT has full visibility of X1 and X2. Your code would also have worked if you did this:
data test;
infile datalines;
input x1 x2 x3 x4;
return;
datalines;
1 2 3 4
1 1 4 4
5 6 7 7
;
run;
proc report data=test;
column x1 x2 x3 x4;
define x1 / display;
define x2 / display;
define x3 / sum;
define x4 / sum;
compute x2;
if x1 ne x2
then call define(_col_,"style","style={background=orange}");
endcomp;
compute x4;
if x3.sum ne x4.sum
then call define('x3.sum',"style","style={background=orange}");
endcomp;
run;
cynthia
I think I get it. But is it possible to let the variables appear in the sequence x1 x2 and set the style for x1 depending on x2 (or a comparison of x2 and x1)?
Make sure AMTPRE is after AMTPRE96 . AMTEXTFORPAYPERI is after AMTE4PAPE96
In general when you want to do something like this, I recommend to follow these principles:
All analysis variable have an alias (varname=alias), this allows to use the same var more than once, for instance because you need more than one statistic. Also it has the advantage, that you can use the alias name whereever you need this variable name: DEFINE statement, CALL DEFINE routine, assignment statement etc.
Add a computed column at the very end of your COLUMN statement and set the NOPRINT option in the DEFINE statement. You can now code everything you need in the compute block of this computed column. Since it is at the end of the column list, it can access all the variable values to the left.
The code below illustrates this.
data mycars;
set sashelp.cars(obs=10);
if mod(_n_, 3) then do;
msrp = invoice;
end;
run;
proc report data=myCars;
column make model invoice=inv2 msrp=msrp2 _dummy;
define make / display;
define model / display;
define inv2 / analysis sum;
define msrp2 / analysis sum;
define _dummy / computed noprint;
compute _dummy;
if msrp2 > inv2 then do;
call define("msrp2", "style", "style={background=gold}");
call define("inv2", "style", "style={background=cx88e55c}");
end;
endcomp;
run;
Bruno
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: