Help using Base SAS procedures

SAS proc report copmpute

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

SAS proc report copmpute

[ Edited ]

Hi,

Below is the proc report i am trying to run,my objective is to color the date cells where modified_date column values is more than 365 days behind the current date.

I am using compute block for this. I am unable to color the cells of Modified_Date column but i have applied a similar compute for File_Size and the color is coming fine.it seems to me a data type issue, can you please guide me.

Also Please note: Modified_Date is numeric.

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

proc report data=final1 nowd split='~' headline headskip nowd

style(REPORT)={rules=all bordercolor=black cellspacing=1}

style(header)={borderwidth=0 borderspacing=0 backgroundcolor=cx6495ED color=white font_size=16pt font_face='Franklin Gothic Demi Cond'};

column Owner Group Modified_Date File_Size Filename ;

*column ('Business directory utilisation'('As of - "&SYSDATE."' Owner File_Size Modified_Date Filename)) ;

define Owner / STYLE(HEADER)=[JUST=LEFT];

define File_Size / STYLE(HEADER)=[JUST=LEFT];

define Modified_Date / STYLE(HEADER)=[JUST=LEFT];

define Filename / STYLE(HEADER)=[JUST=LEFT];

 compute File_Size;

  if substr(File_Size,1,length(File_Size)-1) > 50 then

   call define    (_col_,"style","style={background=lightgreen}");

  if substr(File_Size,1,length(File_Size)-1) > 100 then

   call define (_col_,"style","style={background=lightblue}");

  if substr(File_Size,1,length(File_Size)-1) > 200 then

   call define(_col_,"style","style={background=lightred}");

endcomp;

compute Modified_Date;

  if intck('days',Modified_Date1,today()) > 365 then

   call define(_col_,"style","style= {background=lightred}");

endcomp;

run;


Accepted Solutions
Solution
‎01-19-2017 04:16 AM
SAS Employee
Posts: 4

Re: SAS proc report copmpute

Sharique,

Modified_date is numeric.  Numeric variables have to be referenced by name.statistic inside a compute block, so you would need Modified_date.sum in that statement. 

But you probably don't actually want to sum a date, so add DISPLAY to the DEFINE statement and leave the compute block alone.

define Modified_Date / DISPLAY STYLE(HEADER)=[JUST=LEFT];

 

I also noticed a typo.  In the compute block you have Modified_Date1 not Modified_Date.  

 

 

View solution in original post


All Replies
Super User
Super User
Posts: 7,979

Re: SAS proc report copmpute

Well, personal opinion here.  I really don't like doing calculations and things in a reporting procedure.  Have a datastep which adds a flag into your data (which gets set to non printed in your report), and then use that flag to apply coloring.

Super User
Posts: 11,343

Re: SAS proc report copmpute

Supply some example data in the form of datastep so we could test your code. The example data should have at least one case for each output to test. https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... shows how to generate datastep code from a dataset.

 

What format is currently assigned to your date variable?

Occasional Contributor
Posts: 5

Re: SAS proc report copmpute

Hi,

to give a general example to work with.
Please find a code below:
could you please help me know how can i highlight date cells where the difference bithween that date value and current date > 365.

>>>>>>>>>>>>>>>>>>>>>>>>>>

data new;
set sashelp.buy;
run;
proc report data=new;
column amount date;
define amount /center;
define date / center;
compute date;
if intck('day',date,date()) > 365 then call define(_col_,"style","style={background=lightred}");
endcomp;
run;
Solution
‎01-19-2017 04:16 AM
SAS Employee
Posts: 4

Re: SAS proc report copmpute

Sharique,

Modified_date is numeric.  Numeric variables have to be referenced by name.statistic inside a compute block, so you would need Modified_date.sum in that statement. 

But you probably don't actually want to sum a date, so add DISPLAY to the DEFINE statement and leave the compute block alone.

define Modified_Date / DISPLAY STYLE(HEADER)=[JUST=LEFT];

 

I also noticed a typo.  In the compute block you have Modified_Date1 not Modified_Date.  

 

 

Occasional Contributor
Posts: 5

Re: SAS proc report copmpute

Posted in reply to JaneEslinger
Hi Jane,
A you id i tried with display option.
I tried with a sample code as below and i was able to color the date column . I similarly tried in my main code and it worked.
Thanks alot the solution.Really appreciate this.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

data new;
set sashelp.buy;
run;
proc report data=new;
column amount date;
define amount /display;
define date / display;
compute date;
if intck('day',date,date()) > 365 then call define(_col_,"style","style={background=lightred}");
endcomp;
run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 166 views
  • 0 likes
  • 4 in conversation