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
- /
- SAS Procedures
- /
- How assign result of procedure to one variable?

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-21-2016 11:38 AM

How i can assign result of procedure to variable?

For example i need assign standard deviation value to variable SD from

PROC MEANS STD DATA = smoke3;

run;

So i can use it to find margin of error:

me=SD/sqrt(n);

Thank you

Accepted Solutions

Solution

04-28-2016
12:00 PM

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

04-21-2016 12:07 PM

Generate a data set with the summary values you want and then in a data step do additional calculations:

I tend to prefer Proc summary which does basically the same as proc means but default output sets are structured differently.

Here is an example using the SASHELP.Class data set. Proc summary will require the names of the analyis variables, a variable list, or use of the keyword _numeric_ on the VAR statement. The autoname creates output variables named as your input variables with a suffix of the statistic requested.

```
Proc summary data=sashelp.class;
var Age Height Weight;
output out=work.sum std= n= /autoname;
run;
data want;
set work.sum;
AgeMe = age_StdDev/sqrt(Age_N);
HeightMe = Height_StdDev/sqrt(Height_N);
WeightMe = Weight_StdDev/sqrt(Weight_N);
run;
```

All Replies

Solution

04-28-2016
12:00 PM

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

04-21-2016 12:07 PM

Generate a data set with the summary values you want and then in a data step do additional calculations:

I tend to prefer Proc summary which does basically the same as proc means but default output sets are structured differently.

Here is an example using the SASHELP.Class data set. Proc summary will require the names of the analyis variables, a variable list, or use of the keyword _numeric_ on the VAR statement. The autoname creates output variables named as your input variables with a suffix of the statistic requested.

```
Proc summary data=sashelp.class;
var Age Height Weight;
output out=work.sum std= n= /autoname;
run;
data want;
set work.sum;
AgeMe = age_StdDev/sqrt(Age_N);
HeightMe = Height_StdDev/sqrt(Height_N);
WeightMe = Weight_StdDev/sqrt(Weight_N);
run;
```

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

04-21-2016 11:57 AM

How i can assign result of procedure to variable?

For example i need assign standard deviation value to variable SD from

PROC MEANS STD DATA = smoke3;

run;

So i can use it to find margin of error:

me=SD/sqrt(n);

Thank you

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

04-21-2016 12:27 PM

Create an output dataset with the output statement in proc means. Then run a data _null_ step from that dataset and use call symput to create a macro variable.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

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

04-21-2016 12:41 PM

One other solution, because sometimes you want the statistics back in the original data set is to SET it back in.

The variables from proc summary will be added to the want data set for inclusion.

PS if you're looking to standardize or scale variables also take a look at PROC STANDARD and STDIZE.

```
Proc summary data=sashelp.class;
var Age Height Weight;
output out=work.sum std= n= /autoname;
run;
data want;
if _n_ = 1 then set sum;
set sashelp.class;
run;
```

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

04-21-2016 09:47 PM

That is called standard error . You don't need another SAS statement to calculated it. PROC MEANS would do it for you .

proc means data=sashelp.class std stderr; var Age Height Weight; run;