Have..
State | BiWeekly_target | wk | Reached_status |
AK | 15 | 2021-02-14 To 2021-02-20 | 12 |
AL | 11 | ||
AR | 8 | ||
AZ | 12 | 2021-02-07 To 2021-02-13 | 8 |
CO | 10 | 2021-02-14 To 2021-02-20 | 9 |
CT | 11 | 2021-02-14 To 2021-02-20 | 11 |
DC | 16 | 2021-02-07 To 2021-02-13 | 12 |
DE | 9 | 2021-02-14 To 2021-02-20 | 9 |
Want
week | ||||||
2021-02-07 To 2021-02-13 | 2021-02-14 To 2021-02-20 | Reached_status | ||||
state | BiWeekly_target | Diff | %Diff | |||
AK | 15 | - | 12 | 12 | 3 | |
AZ | 18 | 8 | - | 8 | 10 | |
CO | 10 | - | 9 | 9 | 1 | |
CT | 11 | - | 11 | 11 | 0 | |
DC | 16 | 12 | - | 12 | 4 | |
DE | 9 | - | 9 | 9 | 0 |
So far tried the following..
ODS excel options(sheet_name=' Counts ' autofilter='all' embedded_titles='yes' embedded_footnotes='yes'
absolute_column_width='10,45,15,25,25,15' flow = "header, data");
proc report data=target_stat nowd SPLIT='*' ;*completerows;
column state BiWeekly_target Category, Reached_status ('Total' Reached_status =tot);;
define state / group width= 45 " Submitter";
define BiWeekly_target / group width= 45 " BiWeekly * Target";
define Category/ across width= 30 order= Internal "week ";
define Reached_status / sum width= 30 " ";
define tot / sum ' ';
run;
Need to achieve..
1) Show all states irrespective of reached_status For ex: AL & AR- completerows is not working as desired
2) Add new column in report to show the difference BiWeekly_target- Reached_status
3) Add another column to show the percent difference.
4) Color, if difference is zero then target reached so it should be green, If diff greater than 75% then it should be yellow
otherwise red.
5) Is it possible to wrap the second row in the report( dates row)?
thank you
Hi:
I don't understand what you mean about rounding to 100% if the total is greater than the BiWeekly_Target. I don't understand why your calculation multiplies by 100 because the percent format that you've using also multiplies by 100, so I just changed your formula a bit. In order to use BiWeekly_Target in any calculation, you must use the compound name BiWeekly_Target.sum because BiWeekly_Target is an analysis variable with a usage of SUM. I also wasn't clear on the percents. The issue with your data, as you sent it is that you have missing values for WK for both AL and AR, so they don't have a place to fit under. Also your REACHED_STATUS for thos 2 rows is going to be missing, which will mess up the DIFF calculation and the percent calculation. I did the color coding that made sense to me, you might need to tweak it.
Here's the slightly changed data and code I used:
Note that I moved a lot of the column headers up into the column statement itself in order to simplify the headers for the ACROSS variables.
And the output -- I only did the red and green because I did not really understand the rounding your envision. Also, see how AL and AR have 0 under the missing column for WK -- if their week value is missing and their reached_status value is missing, then there is no difference that can be calculated for them:
Hope this helps,
Cynthia
@Stalk wrote:
Have..
State BiWeekly_target wk Reached_status AK 15 2021-02-14 To 2021-02-20 12 AL 11 AR 8 AZ 12 2021-02-07 To 2021-02-13 8 CO 10 2021-02-14 To 2021-02-20 9 CT 11 2021-02-14 To 2021-02-20 11 DC 16 2021-02-07 To 2021-02-13 12 DE 9 2021-02-14 To 2021-02-20 9 Want
week 2021-02-07 To 2021-02-13 2021-02-14 To 2021-02-20 Reached_status state BiWeekly_target Diff %Diff AK 15 - 12 12 3 AZ 18 8 - 8 10 CO 10 - 9 9 1 CT 11 - 11 11 0 DC 16 12 - 12 4 DE 9 - 9 9 0 So far tried the following..
ODS excel options(sheet_name=' Counts ' autofilter='all' embedded_titles='yes' embedded_footnotes='yes'
absolute_column_width='10,45,15,25,25,15' flow = "header, data");proc report data=target_stat nowd SPLIT='*' ;*completerows;
column state BiWeekly_target Category, Reached_status ('Total' Reached_status =tot);;
define state / group width= 45 " Submitter";
define BiWeekly_target / group width= 45 " BiWeekly * Target";
define Category/ across width= 30 order= Internal "week ";
define Reached_status / sum width= 30 " ";
define tot / sum ' ';
run;Need to achieve..
1) Show all states irrespective of reached_status For ex: AL & AR- completerows is not working as desired
2) Add new column in report to show the difference BiWeekly_target- Reached_status
3) Add another column to show the percent difference.
4) Color, if difference is zero then target reached so it should be green, If diff greater than 75% then it should be yellow
otherwise red.
5) Is it possible to wrap the second row in the report( dates row)?
thank you
1) Your code shows *completerows; which would comment the option and not be used.
Your columns statement shows a variable name Category that you do not show as being in your "have" data.
Your output shows a column heading of "week" for the non-existant variable Category
So I don't think you are showing either the code or the data you are actually using.
Start over providing actual data, in the form of a data step that will allow us to recreate a partial data set that will run with the code. Double check your code and post a corrected version that matches the data.
Hi:
I don't understand what you mean about rounding to 100% if the total is greater than the BiWeekly_Target. I don't understand why your calculation multiplies by 100 because the percent format that you've using also multiplies by 100, so I just changed your formula a bit. In order to use BiWeekly_Target in any calculation, you must use the compound name BiWeekly_Target.sum because BiWeekly_Target is an analysis variable with a usage of SUM. I also wasn't clear on the percents. The issue with your data, as you sent it is that you have missing values for WK for both AL and AR, so they don't have a place to fit under. Also your REACHED_STATUS for thos 2 rows is going to be missing, which will mess up the DIFF calculation and the percent calculation. I did the color coding that made sense to me, you might need to tweak it.
Here's the slightly changed data and code I used:
Note that I moved a lot of the column headers up into the column statement itself in order to simplify the headers for the ACROSS variables.
And the output -- I only did the red and green because I did not really understand the rounding your envision. Also, see how AL and AR have 0 under the missing column for WK -- if their week value is missing and their reached_status value is missing, then there is no difference that can be calculated for them:
Hope this helps,
Cynthia
Hi:
I rarely use autofilter and when I do, I NEVER use ALL as the option. Usually, I have numeric variables in my output and I only like having autofilter on my character variables because those are usually the values I want to filter on. However, when I use ODS EXCEL with the same PROC REPORT code as previous posted, I do get autofilter on all the columns:
But as I said, in this context, it doesn't make sense to me to have autofilter on anything other than the first column. The reason is that it doesn't make sense to work so hard at getting a particular structure to the output only to go and use autofilter on ALL the columns for this data. My inclination would be to just put autofilter like this:
If you're having issues with autofilter, that's something you may want to work out with Tech Support. They have the ability to look at all your real data and your real code and take your version of SAS into account to help you come to a resolution.
Cynthia
Hi:
Then I would probably change the COMPUTE block to alter and then do the highlighting based on the values of DIFF_PCT, as shown below:
Remember that the format is doing the multiply by 100 so the values you have to test are the decimal values after the division but before the format is applied.
Cynthia
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.
Ready to level-up your skills? Choose your own adventure.