turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- "If...then...delete;" issue

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-12-2017 07:35 PM

I want to run a PROC REG on some data with many variables. However, some of the variables were collected at the plot level while others were collected in transects within the plot. If i take the mean of the transect variables, that gives me a plot level variable that i can then use the PROC REG function on. However, if i use PROC MEANS to get the mean variable of these transect data points it also gives me N, MAX, MIN, and STD output. If i run PROC REG on the data generated by PROC MEANS it includes the 4 variables i mentioned in the regression, which i obviously don't want. So, i want to delete those 4 variables and have PROC REG use the MEAN variable exclusively.

proc means data=AllEvents;

class plotID;

var logN2O logVWC Soil_N Soil_C SoilC_N LitterN LitterC LitterC_N pH_H2O pH_CaCl2 logNH4 logTN;

output out=plotmeans;

run;

data plotmeans;

if "_STAT_"="N" then delete;

if "_STAT_"="MAX" then delete;

if "_STAT_"="MIN" then delete;

if "_STAT_"="STD" then delete;

output;

run;

The proc means command works fine but the my "if...then...delete;" command doesn't work. It doesn't generate an error, but it does give me the message: NOTE: Variable _STAT_ is uninitialized.

How can i generate an output of the mean of the variables i'm interested in at the plot level that i can then run PROC REG with?

Accepted Solutions

Solution

10-13-2017
03:14 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AaronJ

10-13-2017 12:35 AM

If you just want PROC MEANS to generate the MEAN then tell it that. If you add MEAN= to the OUTPUT statement then SAS will store the means into the variables with the same names as the input variables.

```
proc means data=AllEvents;
class plotID;
var logN2O logVWC Soil_N Soil_C SoilC_N
LitterN LitterC LitterC_N pH_H2O pH_CaCl2 logNH4 logTN
;
output out=plotmeans mean=;
run;
```

Your data step has a number of problems. First you are not telling it what data to read. Second you are comparing two string literals in your IF statements that can never be equal. You probably could have gotten it to work with code like this just use a subsetting IF instead of IF/THEN/DELETE.

```
data plotmeans;
set plotmeans;
if _stat_='MEAN';
run;
```

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AaronJ

10-12-2017 07:51 PM

You can control the output in various ways. Look at the OUTPUT statement documentation for starters to select only the MEAN.

And then look at the STACKODS option to see if you want a different structure.

```
proc means ...;
....
output out=want mean = /autoname;
run;
```

or

```
proc means data=... MEAN STACKODS;
....
ods output summary=want_stacked;
run;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AaronJ

10-12-2017 07:51 PM

You need a set statement after the data statement:

set plotmeans;

It reads the input data set into the data step.

Solution

10-13-2017
03:14 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AaronJ

10-13-2017 12:35 AM

If you just want PROC MEANS to generate the MEAN then tell it that. If you add MEAN= to the OUTPUT statement then SAS will store the means into the variables with the same names as the input variables.

```
proc means data=AllEvents;
class plotID;
var logN2O logVWC Soil_N Soil_C SoilC_N
LitterN LitterC LitterC_N pH_H2O pH_CaCl2 logNH4 logTN
;
output out=plotmeans mean=;
run;
```

Your data step has a number of problems. First you are not telling it what data to read. Second you are comparing two string literals in your IF statements that can never be equal. You probably could have gotten it to work with code like this just use a subsetting IF instead of IF/THEN/DELETE.

```
data plotmeans;
set plotmeans;
if _stat_='MEAN';
run;
```