Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Re: Extracting values from PROC MEANS, use them in a new table to comp...

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-11-2019 09:09 AM
(615 views)

Hi, I'm looking for a fancy way to solve my problem. Even though the code is doing what I need I am not happy with it.

What I need is to take values from two OUTPUTs obtained by PROC LOGISTIC and PROC MEANS.

How can I assign the mean value obtained from PROC MEANS to a new variable? In this case, I have two means, one where the class is 1 and the other when the class is 0. Therefore, I need to create a variable called mean_y_1 and mean_y_0. I assigned those values by hand, how can I do using functions?. Check the code below.

Thank you.

```
DATA ORIGINAL;
INPUT ID Y CLASS;
CARDS;
1 12000 1
2 0 0
3 0.6 0
4 0.7 1
5 19 0
;
RUN;
PROC LOGISTIC DATA = ORIGINAL PLOT = NONE OUTEST = LOGIT_ESTIMATESS;
MODEL CLASS(EVENT = '1')= Y /; RUN;
PROC MEANS DATA = ORIGINAL n MEAN STD MAXDEC = 4;
CLASS CLASS; VAR ID; OUTPUT OUT= ORIGINAL_MEANS MEAN= MEAN_Y; RUN;
/* TAKING VALUES FROM LOGIT_ESTIMATES AND ORIGINAL_MEANS. BOTH TABLES ARE THE OUTPUT OF
```

PROC LOGISTIC AND PROC MEANS */
DATA ORIGINAL_ANALYSIS; DROP _FREQ_ _TYPE_ ; SET LOGIT_ESTIMATESS;
/* ASSIGNING THE MEAN VALUE BY CLASS */
MEAN_Y_1 = 3.3333;
MEAN_Y_0 = 2.5000;
/* WHEN CLASS = 1 */
STEP1_1 = INTERCEPT + (Y * MEAN_Y_1) ;
/* WHEN CLASS = 0 */
STEP1_0 = INTERCEPT + (Y * MEAN_Y_0) ;
FORMAT STEP1_1 STEP1_0 COMMA32.31;
LABEL STEP1_1 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
LABEL STEP1_0 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
RUN;
PROC PRINT DATA = ORIGINAL_ANALYSIS LABEL; FORMAT STEP1_1 STEP1_0 COMMA10.4 ;VAR STEP1_1 STEP1_0 ; RUN;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

a fix

```
PROC MEANS DATA = ORIGINAL n MEAN STD MAXDEC = 4 nway;
CLASS CLASS; VAR ID; OUTPUT OUT= ORIGINAL_MEANS MEAN= MEAN_Y; RUN;
DATA ORIGINAL_ANALYSIS; SET LOGIT_ESTIMATESS;
if _n_=1 then do;
set ORIGINAL_MEANS(firstobs=1 keep=mean_y rename=(mean_y= MEAN_Y_0));
set ORIGINAL_MEANS(firstobs=2 keep=mean_y rename=(mean_y= MEAN_Y_1));
end;
/* ASSIGNING THE MEAN VALUE BY CLASS */
/* MEAN_Y_1 = 3.3333;*/
/* MEAN_Y_0 = 2.5000;*/
/* WHEN CLASS = 1 */
STEP1_1 = INTERCEPT + (Y * MEAN_Y_1) ;
/* WHEN CLASS = 0 */
STEP1_0 = INTERCEPT + (Y * MEAN_Y_0) ;
FORMAT STEP1_1 STEP1_0 COMMA32.31;
LABEL STEP1_1 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
LABEL STEP1_0 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
RUN;
```

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

a fix

```
PROC MEANS DATA = ORIGINAL n MEAN STD MAXDEC = 4 nway;
CLASS CLASS; VAR ID; OUTPUT OUT= ORIGINAL_MEANS MEAN= MEAN_Y; RUN;
DATA ORIGINAL_ANALYSIS; SET LOGIT_ESTIMATESS;
if _n_=1 then do;
set ORIGINAL_MEANS(firstobs=1 keep=mean_y rename=(mean_y= MEAN_Y_0));
set ORIGINAL_MEANS(firstobs=2 keep=mean_y rename=(mean_y= MEAN_Y_1));
end;
/* ASSIGNING THE MEAN VALUE BY CLASS */
/* MEAN_Y_1 = 3.3333;*/
/* MEAN_Y_0 = 2.5000;*/
/* WHEN CLASS = 1 */
STEP1_1 = INTERCEPT + (Y * MEAN_Y_1) ;
/* WHEN CLASS = 0 */
STEP1_0 = INTERCEPT + (Y * MEAN_Y_0) ;
FORMAT STEP1_1 STEP1_0 COMMA32.31;
LABEL STEP1_1 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
LABEL STEP1_0 = 'AVERAGE METHOD PROBABILITY OF CLASS = 1';
RUN;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks that's what I was looking.

Works perfectly.

Cheers

⏰

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.** **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.