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).

Bhupinder
Valued Guide
Posts: 2,191

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

sounds like a stats question. Have you tried the Stats forum? It is at http://support.sas.com/forums/forum.jspa?forumID=46
Contributor
Posts: 22

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

Hi Peter,

No, I didn't post but will do now. Thanks for letting me know. Can you please suggest if there are more forums to get stat models' help especially MIXED model and repeated measures and for Analysis of Covariance.

Thanks
Bhupinder
Super User
Posts: 13,542

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

One guesses that the syntax you attempted maybe should have read:

IF CROP = 'corn' THEN DELETE; /* must match the spelling and case of the value */

unless you intended to check if the value of the variable CROP was the same as the variable CORN.

Unless you really want to proliferate data sets, specifying a WHERE statement such as:
WHERE CROP='corn'
or
DATA=SOILS (where=(crop='corn')) in the proc call,
will accomplish the subset for any procs that do not directly support a where statement
Contributor
Posts: 22

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

While createing subsetting of data. Is it possible to use multiple commands like IF and WHERE.

data want;
set soils where=(upcase(crop) ne 'CORN'));
where=(upcase(crop) ne 'SOYBEAN'));
IF sampling_stage = "F1" then delete;

RUn;

This code is not working. can you please suggest any improvement in it?
Super User
Posts: 23,724

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

You can specify multiple conditions using "and" or the in/not in function.

data want;
set sashelp.class;
where age ne 13 and age ne 14;
run;

OR

data want;
set sashelp.class;
where age not in (13, 14);
run;
Contributor
Posts: 22

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

can you see if following code is correct?

data want;
set soils;
where crop not in ('Corn', 'Soybean') and field ne 'F1';
run;
Super User
Posts: 23,724