I have data for Survival collected from 4 plots in 4 blocks (n=16, N=4) marked as Y or N, so i used Proc FREQ via:
PROC FREQ data=TreesSAS;
by Species Measurement Fert Nfix;
TABLES Survival;
RUN;
and it generated a tables for each tree species, by measurement (Date) and treatment (Fert and Nfix), withe accompanying frequency, percent, cum. freq. and cum. perc.
Since Y and N are not numbers, they can't be analyzed for variance, but i would like to generate a standard deviation value for this data.
I tried using output out=Survival and then using the Proc Means statement with data=Survival, but the error message says that Survival does not exist.
How can i generate a Standard Deviation value for Survival in my data set?
%web_drop_table(WORK.IMPORT);
FILENAME FILEREF '/folders/myfolders/TreesSAS.xlsx';
PROC IMPORT DATAFILE=FILEREF
DBMS=XLSX
OUT=WORK.IMPORT;
GETNAMES=YES;
RUN;
data TreesSAS;
set import;
if Leave='Y' then Delete;
if row=1 then Delete;
if row=6 then Delete;
if Tree=1 then Delete;
if Tree=13 then Delete;
run;
@AaronJ wrote:
The Y / N variable is "Survival", simply a column indicating that the tree is alive.
So I took you up on your idea, and entered
if Survival= 'Y' then 1;
if Survival='N' then 0;
in the data step
and it gave me the Statement is not valid or used out of proper order error message.
How/where should i include this modification?
thanks
data TreesSAS;
set import;
if Leave='Y' then Delete;
if row=1 then Delete;
if row=6 then Delete;
if Tree=1 then Delete;
if Tree=13 then Delete;
if Survival='N' then 0;
if Survival='Y' then 1;
logGLD=log(GLD);
logDBH=log(DBH);
logHt=log(Ht);
run;
If you want to assign a value to a variable you have to reference the target variable:
Instead of:
if Survival='N' then 0;
if Survival='Y' then 1;
use:
if Survival='N' then SurvivalNum=0;
if Survival='Y' then SurvivalNum=1;
Which variable(s) are coded Y N? Not at all clear.
Since you are already using a data step to modify your data it might be worth creating a numeric 0/1 coding (1=Y_.
Then go directly to proc means using the 0/1 coded variable. The mean will be the percentage of Y values with a corresponding deviation.
add a class statement to proc means to get summary statistics with in your groups.
Assuming you name that numeric variable SurvivalNum:
proc means data=treesSAS; class Species Measurement Fert Nfix; types Species Measurement Fert Nfix; var SurvivalNum; RUN;
the Types statement lets select combinations of things for the summary. You could add Species*Fert to get a summary of SurvivalNum for combinations of those two.
The Y / N variable is "Survival", simply a column indicating that the tree is alive.
So I took you up on your idea, and entered
if Survival= 'Y' then 1;
if Survival='N' then 0;
in the data step
and it gave me the Statement is not valid or used out of proper order error message.
How/where should i include this modification?
thanks
data TreesSAS;
set import;
if Leave='Y' then Delete;
if row=1 then Delete;
if row=6 then Delete;
if Tree=1 then Delete;
if Tree=13 then Delete;
if Survival='N' then 0;
if Survival='Y' then 1;
logGLD=log(GLD);
logDBH=log(DBH);
logHt=log(Ht);
run;
@AaronJ wrote:
The Y / N variable is "Survival", simply a column indicating that the tree is alive.
So I took you up on your idea, and entered
if Survival= 'Y' then 1;
if Survival='N' then 0;
in the data step
and it gave me the Statement is not valid or used out of proper order error message.
How/where should i include this modification?
thanks
data TreesSAS;
set import;
if Leave='Y' then Delete;
if row=1 then Delete;
if row=6 then Delete;
if Tree=1 then Delete;
if Tree=13 then Delete;
if Survival='N' then 0;
if Survival='Y' then 1;
logGLD=log(GLD);
logDBH=log(DBH);
logHt=log(Ht);
run;
If you want to assign a value to a variable you have to reference the target variable:
Instead of:
if Survival='N' then 0;
if Survival='Y' then 1;
use:
if Survival='N' then SurvivalNum=0;
if Survival='Y' then SurvivalNum=1;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.