Programming the statistical procedures from SAS

Creating subset of data and calculate weighted means for depth

Reply
Contributor
Posts: 22

Creating subset of data and calculate weighted means for depth

Hi,

I want to create subset of data based on one level of independent variable. I have used the following code to create subset of the data but it didn't work.

data spring07; set soils;
if crop = corn then delete;
run;

Is there any way to model with variable ne (^=). I did try but it is not working.

My second question is to calculate weighted means based on depths from that particular subset of data. I want to get weighted means of Phos variable based on depth as per following formula

Phos(weighted0-40) = (5*Phos1 + 5*Phos2 + 10*Phos3 + 20*Phos4)/40.

Phos(weighted0-20) = (5*Phos1 + 5*Phos2 + 10*Phos3)/20.

I don't know how I can do that because data has different other variables like Tillplc, Prate, Krate, and sampling location (in-row and between row).

Thanks, in advance!
Bhupinder
Contributor
Posts: 22

Re: Creating subset of data and calculate weighted means for depth

At the start of experiment and at the end of each year (2007, 2008, and 2009) we measured soil parameters (phosphorus, potassium, calcium, and magnesium) to quantify the effect of treatments at different depths and different parts of the plots, aka, “loc” (IR-at the planting row; BR- between two planting rows). My second question in the original post came from the idea to quantify how much soil phosphorus increased or decreased for top 18 cm (weighted means of 0-5, 5-10, and 10-18) at the end of each year from initial values as well as from the first year. This can be calculate for locations separately and also for overall each plot.

Soybean experiment (2007 – 09) was planned as RCBD with split split plot arrangements of treatments with three replications. Three tillage treatments (NTBC, NTDP, and STDP) were done in three blocks as main treatments which I am calling as whole plots. Each block (whole plot) was divided into four parts to apply four phosphorus levels (0, 12, 24, and 36 kg/ha) which I am calling as sub-plots. These sub-plots were further divided into four parts to apply four potassium levels (0, 42, 84, and 168 kg/ha) which I am calling as sub-sub-plots or “PLOTS”. For year 2008 and 2009, we sampled all the plots but in the third year, we sampled plots only receiving 5 particular fertility treatments out of 16 combinations of P and K. Therefore, I have fertility (P-K) as category.

We sampled soil at two particular “locations” (within two planting rows and at the planting rows) and four depths (0-5, 5-10, 10-20, and 20-40) within PLOTS.

To handle this analysis, I need to subset this data for each MIXED model. I just want to keep only one data file to avoid confusion.

Thanks
Bhupinder
Grand Advisor
Posts: 9,458

Re: Creating subset of data and calculate weighted means for depth

>Is there any way to model with variable ne (^=). I did try but it is not working.


Yes. proc mixed data=spring07(where crop ne 'corn' ) ......


>Phos(weighted0-40) = (5*Phos1 + 5*Phos2 + 10*Phos3 + 20*Phos4)/40.

You can just make hard code to get it.

data sprint0;
Phos_weighted= (5*Phos1 + 5*Phos2 + 10*Phos3 + 20*Phos4)/40.


BTW, the best way to get your answer is to give your origin data and what your output looks like.

Ksharp
Valued Guide
Posts: 632

Re: Creating subset of data and calculate weighted means for depth

Notice that KSharp placed quotes around the literal 'corn'. This comparison is case sensitive.

Also observe the way that the variable is named in the equation. Naming conventions must be followed.
Grand Advisor
Posts: 9,458

Re: Creating subset of data and calculate weighted means for depth

Dear Arther Carpenter:
I do not know to say what.


Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 4 replies
  • 96 views
  • 0 likes
  • 3 in conversation