BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AaronJ
Obsidian | Level 7

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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;

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

 

AaronJ
Obsidian | Level 7

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;

ballardw
Super User

@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;

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1918 views
  • 0 likes
  • 2 in conversation