|
Bhupinder
Thank you for posting the code. Are you running V9.2? If so, you can
eliminate the Proc Import and use the excel file as if it were a SAS data
set.
I seldom used Proc Import and my SAS copy will not read the Excel engine so
I cannot test a variation of your code.
Please post the log for your two data steps. That would tell us a lot. Also,
how may crops are in the soils data set?
I will be away from the computer for a while but the log would really help
anyone else who is on line.
Nat
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Bhupinder Farmaha
Sent: Monday, January 10, 2011 10:40 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Creating subset of data and calculate weighted means for depth
Hi Nat,
I made code with " " and the one your suggested. But, unfortunately, none of
them not worked. I am posting my code complete code here to see if there is
something wrong.
PROC IMPORT OUT= WORK.Soils
DATAFILE= "C:\Users\Bhupinder\Desktop\Roots, soil, and soil
water\PKCSSoildata200709.xls"
DBMS=EXCEL REPLACE;
RANGE="CompleteCS$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
data Soils;
set Soils;
Phos1=Phos*1;
Potas1=Potas*1;
Calc1=Calc*1;
Magn1=Magn*1;
drop Phos;
drop Potas;
drop Calc;
drop Magn;
rename Phos1=Phos;
rename Potas1=Potas;
rename Calc1=Calc;
rename Magn1=Magn;
run;
data soils; set soils;
if crop = "corn" then delete;
if crop = "soybean" then delete;
run;
proc print data = soils;
run;
Thanks
Bhupinder
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nat
Wooding
Sent: Monday, January 10, 2011 9:19 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Creating subset of data and calculate weighted means for depth
Bhupinder
In your code, the line
If crop = corn then delete;
Will not work as you wish for at least one reason, that corn is not enclosed
in quotation marks. This assumes that you want to select the crop called
"corn". As the code stands, the statement will attempt to test the value of
the variable Crop with the value of another variable, Corn which I presume
does note exist in set Soils. Take a look at the log of the following code.
data crops;
informat crop $10.;
input crop @@;
cards;
corn
corn
wheat
rye
barley
run;
Data wanted;
set crops;
if crop = corn;
run;
If you enclose Corn in quotation marks, then the If statement will work.
Your If statement, with quotations, would delete all data for Corn. Is this
what you want or do you wish to select the values for corn? Without a sample
of your data, I can only guess.
I am going to ignore your second question for the moment until we get the
first one resolved.
Nat Wooding
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Bhupinder Farmaha
Sent: Monday, January 10, 2011 10:00 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: 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
|