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

 

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
novinosrin
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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;
OscarUvalle
Obsidian | Level 7

Thanks that's what I was looking.

Works perfectly.

Cheers

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1066 views
  • 3 likes
  • 2 in conversation