Solved
Contributor
Posts: 27

# generating standard deviation from PROC FREQ out put

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;

Accepted Solutions
Solution
‎04-24-2018 04:52 PM
Super User
Posts: 13,913

## Re: generating standard deviation from PROC FREQ out put

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

if Survival='N' then 0;
if Survival='Y' then 1;

use:

if Survival='N' then SurvivalNum=0;
if Survival='Y' then SurvivalNum=1;

All Replies
Super User
Posts: 13,913

## Re: generating standard deviation from PROC FREQ out put

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.

Contributor
Posts: 27

## Re: generating standard deviation from PROC FREQ out put

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;

Solution
‎04-24-2018 04:52 PM
Super User
Posts: 13,913

## Re: generating standard deviation from PROC FREQ out put

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

if Survival='N' then 0;
if Survival='Y' then 1;

use:

if Survival='N' then SurvivalNum=0;
if Survival='Y' then SurvivalNum=1;

☑ This topic is solved.