I am using the attached code to establish a ratio of sold to bought products.
What I want to do however is:
A) Control the order of the variables which are returned to me (product) so that they are no longer in alphabetical order.
B) Include an additional variable which is called "Total Fresh" and a variable called "Total Processed" so that products which are tinned or frozen are used to calculate the Total Processed ratio, whilst non-tinned and non-frozen products calculate the Total Fresh ratio (there is presently no variable to denote this).
Is anyone able to give me any advice on this?
options nodate pageno=1 linesize=64
proc report Data=Merged nowd Out = Frequency headline headskip;
column yr mth Product, (Sold Bought Frequency);
define Product / Across ' ';
define Yr / Group ' ' noprint;
define Mth / Group ' ';
define Bought / Analysis format = comma12.6 Sum noprint;
define Sold / Analysis format = comma12. Sum noprint;
define Ratio / Computed format = percent9.2 ' ';
I'm not sure I understand all of what you want to do. However, as far as getting the across variable in the order you want, look at this example: http://support.sas.com/forums/thread.jspa?messageID=19625䲩
especially the use of the ACCORD variable in the example and the ORDER=DATA option of the DEFINE statement.
To help you with your problem description, generally, you refer to report items which come from your dataset as "variables" and then you refer to other items (such as COMPUTED usage items) as "report items". What is not clear to me is how the Total Fresh Ratio or the Total Processed Ratio report items should be calculated. They seem to be based only on the type of product??? You don't show a "type" variable in your COLUMN statement. Since you can control the order of the ACROSS variables, the answer could be as simple as using the different column numbers in different compute blocks (I made up these column numbers):
Thank you for your help. I have attached an example of what I am trying to do. I have used the sashelp.class dataset (although the meaures I am using make no sense, the outcomes should remain apparent). The only difference in what I am looking to achieve is that I have a variable called month which I have defined as a group variable, allowing me to see historical movement.
I have sorted the data so that all names associated with males appear after those relating to females. I now wish to add a variable between the start of the male names and the end of the female names called females and in that I wish to calculate the HWRatio of all the females. I wish to do the same for the males and have this figure presented following the final male name.
I hope that this better explains my desired outcomes. Once again I am very greatful for your assistance.
Proc Sort data = sashelp.class out = class;
by sex name;
proc report Data=class out = classreport nowd headline headskip;
column Name, (weight height HWRatio);
define Name / Across ' ' order = data;
define weight / Analysis format = comma12.6 Sum noprint;
define height / Analysis format = comma12.0 Sum noprint;
define HWRatio / Computed format = percent9.2 ' ';
It seems to me that you are saying you want to add a new calculated report item as a new across item, but not under each name? Instead, after the female names, you want a ratio for females only and after the male names, you want to calculate a ratio for males only.
With your present ACROSS variables, you will have a hard time doing that. The only way that I can imagine doing it is for you to also use the SEX variable as an ACROSS variable on the report. For example, I have limited the CLASS data to only 6 observations -- 3 Females and 3 Males, for ease of illustration.
proc sort data = sashelp.class out = class;
where name in ('Alfred', 'William', 'John','Alice','Barbara', 'Jane');
by sex name;
The only complicating factor of this method is that the column numbers are set based on the total number of possible across (6) under each gender times the total number of columns under each name (6*3 =18). This means you need the NOCOMPLETECOLS to keep the unused across values from showing up under each gender value. This also means that even with 3 names for females, absolute column numbers are assigned to the 3 names for males, even if they're not going to be used, which means that column _C19_ will become the calculated gender ratio for females and _c38_ will become the calculated gender ratio for males.