BookmarkSubscribeRSS Feed
Bhupinder
Calcite | Level 5
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
7 REPLIES 7
Peter_C
Rhodochrosite | Level 12
sounds like a stats question. Have you tried the Stats forum? It is at http://support.sas.com/forums/forum.jspa?forumID=46
Bhupinder
Calcite | Level 5
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
ballardw
Super User
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
Bhupinder
Calcite | Level 5
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?
Reeza
Super User
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;
Bhupinder
Calcite | Level 5
can you see if following code is correct?

data want;
set soils;
where crop not in ('Corn', 'Soybean') and field ne 'F1';
run;
Reeza
Super User
IF the data looks like you want it to it is.

Given that you had the upcase before you probably still need it now.

When comparing strings SAS is case sensitive, ie corn ne Corn so upcasing both will correct for that. ie upcase (corn)="CORN".

HTH

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1364 views
  • 0 likes
  • 4 in conversation