LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 2 Dec 2004 08:16:49 -0500
Reply-To:     Ed Heaton <EdHeaton@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ed Heaton <EdHeaton@WESTAT.COM>
Subject:      Re: Calculating with macro values  (ie comparing to a # in if/the
              n statement)
Comments: To: "DePuy, Venita" <depuy001@DCRI.DUKE.EDU>
Content-Type: text/plain

Venita,

I'm having a slightly hard time following your code. Is this what you want to do? I have changed the %IF statements to IF statements because I don't see the need for them.

%do i=1 %to &nVars ; Proc reg data=out_hetero ; Model res2 = &&var&i &&var&i.._sq ; Ods output parameterEstimates=var_est&i ; Run ; Proc print data=var_est&i ; Run ; Data _null_ ; Set var_est&i end=endOfFile ; If endOfFile ; If ( ( ProbT gt &alpha) or missing(ProbT) ) then call execute( "Proc reg data=out_hetero ;" || " Model res2 = &&var&i ;" || " Ods output parameterEstimates=var_est&i ;" || "Run;" ) ; Run ; Proc print data=var_est&i ; Run ; Data var_est_&i ; Length Variable $20 ; Set var_est&i end=endOfFile ; Where ( variable ne 'Intercept') ; If ( endOfFile & ( ( ProbT lt 0 ) or (ProbT gt &alpha) ) ) then call execute("Data var_est_&i ; Set _null_ ; Run ;") ; Run ; Data hetero_var ; Set hetero_var var_est_&i ; Run ; %end ; Proc print data=hetero_var ; Run ;

Ed

Edward Heaton, SAS Senior Systems Analyst, Westat (An Employee-Owned Research Corporation), 1600 Research Boulevard, RW-3541, Rockville, MD 20850-3195 Voice: (301) 610-4818 Fax: (301) 610-5128 mailto:EdHeaton@Westat.com http://www.Westat.com

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of DePuy, Venita Sent: Wednesday, December 01, 2004 12:27 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Calculating with macro values (ie comparing to a # in if/the n statement)

Hi again - Thanks for all the responses earlier! And you're right, in most cases I was complicating things I didn't need to. But I have one case (so far) where I'm having trouble . .

Background: proc reg, model y = x x^2; if x^2 isn't significant, model y=x; if x isn't significant, set the output file to _null_. It's a method of iteratively looking at heteroscedasticity by regressing residuals from an earlier model. (Yes, I'm sure this is the way I want to do it).

So take the output from the y=x x^2 model, look at the last line, if Probt> &alpha or Probt=. then run the next model; if that model has Probt>&alpha or Probt=. then set that output file =null, since the next step is stacking these outputs into a file w/ data & set statements.

For some reason, my first comparison is working but my second isn't, if that makes sense. In this case trt (a 0/1 variable) is significant, but trt_sq isn't (Probt=. as a 0/1 variable squared is redundant), and trt2 and trt2_sq are not either significant (p's .16,.20)

Code, output, and log follow. Thanks for the help!

Here's the section of code: %do i = 1 %to &nvars; proc reg data=out_hetero ; model res2 = &&var&i &&var&i.._sq; ods output ParameterEstimates = var_est&i; run; proc print data=var_est&i;

data _null_; set var_est&i end=ENDOFFILE; if not ENDOFFILE then delete; %if ((Probt > &alpha) OR (Probt= . )) %then %do; call execute (" proc reg data=out_hetero ; model res2 = &&var&i ; ods output ParameterEstimates = var_est&i;run;"); run;%end;run; proc print data=var_est&i;

data var_est_&i; length Variable $20; set var_est&i end=ENDOFFILE; where variable ne 'Intercept'; %if (ENDOFFILE =1) and ((Probt > &alpha) OR (Probt < 0 ) ) %then %do; call execute ("data var_est_&i; set _null_;run;"); %end;

data hetero_var; set hetero_var var_est_&i; run;

proc print data=hetero_var;

Here's the section of output (print sections only as others would be redundant):

Obs Model Dependent Variable DF Estimate StdErr tValue Probt

1 MODEL1 res2 Intercept 1 0.01052 0.00152 6.94 <.0001 2 MODEL1 res2 trt B 0.01033 0.00303 3.41 0.0008 3 MODEL1 res2 trt_sq 0 0 . . .

Obs Model Dependent Variable DF Estimate StdErr tValue Probt

1 MODEL1 res2 Intercept 1 0.01052 0.00152 6.94 <.0001 2 MODEL1 res2 trt 1 0.01033 0.00303 3.41 0.0008

HETERO_VAR 10:07 Wednesday, December 1, 2004 Obs Variable Model Dependent DF Estimate StdErr tValue Probt

1 trt MODEL1 res2 1 0.01033 0.00303 3.41 0.0008

Estimating variance function heteroscedasticity for: trt2

Obs Model Dependent Variable DF Estimate StdErr tValue Probt

1 MODEL1 res2 Intercept 1 0.01355 0.00166 8.16 <.0001 2 MODEL1 res2 trt2 1 0.00299 0.00160 1.87 0.0633 3 MODEL1 res2 trt2_sq 1 -0.00134 0.00104 -1.28 0.2005

Obs Model Dependent Variable DF Estimate StdErr tValue Probt

1 MODEL1 res2 Intercept 1 0.01245 0.00142 8.75 <.0001 2 MODEL1 res2 trt2 1 0.00187 0.00135 1.39 0.1655

HETERO_VAR

Obs Variable Model Dependent DF Estimate StdErr tValue Probt

1 trt MODEL1 res2 1 0.01033 0.00303 3.41 0.0008 2 trt2 MODEL1 res2 1 0.00187 0.00135 1.39 0.1655

Here's the section of log (tried to remove nonpertinent sections):

MLOGIC(OLS): %DO loop beginning; index variable I; start value is 1; stop value is 2; by value is 1.

NOTE: The data set WORK.VAR_EST1 has 3 observations and 8 variables. NOTE: PROCEDURE REG used (Total process time): NOTE: There were 3 observations read from the data set WORK.VAR_EST1. NOTE: PROCEDURE PRINT used (Total process time):

MLOGIC(OLS): %IF condition ((Probt > &alpha) OR (Probt= . )) is TRUE NOTE: There were 3 observations read from the data set WORK.VAR_EST1. NOTE: DATA statement used (Total process time):

NOTE: CALL EXECUTE generated line. 1 + proc reg data=out_hetero ; model res2 = trt ; odsoutput ParameterEstimates = var_est1;run; NOTE: The data set WORK.VAR_EST1 has 2 observations and 8 variables. NOTE: PROCEDURE REG used (Total process time):

NOTE: There were 2 observations read from the data set WORK.VAR_EST1. NOTE: PROCEDURE PRINT used (Total process time):

MLOGIC(OLS): %IF condition (ENDOFFILE =1) & ((Probt > &alpha) OR (Probt < 0)) is FALSE NOTE: There were 1 observations read from the data set WORK.VAR_EST1. WHERE variable not = 'Intercept'; NOTE: The data set WORK.VAR_EST_1 has 1 observations and 8 variables. NOTE: DATA statement used (Total process time):

NOTE: There were 0 observations read from the data set WORK.HETERO_VAR. NOTE: There were 1 observations read from the data set WORK.VAR_EST_1. NOTE: The data set WORK.HETERO_VAR has 1 observations and 8 variables. NOTE: DATA statement used (Total process time): NOTE: There were 1 observations read from the data set WORK.HETERO_VAR. NOTE: PROCEDURE PRINT used (Total process time):

MLOGIC(OLS): %DO loop index variable I is now 2; loop will iterate again. NOTE: The data set WORK.VAR_EST2 has 3 observations and 8 variables. NOTE: PROCEDURE REG used (Total process time): NOTE: There were 3 observations read from the data set WORK.VAR_EST2. NOTE: PROCEDURE PRINT used (Total process time):

MLOGIC(OLS): %IF condition ((Probt > &alpha) OR (Probt= . )) is TRUE NOTE: There were 3 observations read from the data set WORK.VAR_EST2. NOTE: DATA statement used (Total process time):

NOTE: CALL EXECUTE generated line. 1 + proc reg data=out_hetero ; model res2 = trt2 ; ods output ParameterEstimates = var_est2;run; NOTE: The data set WORK.VAR_EST2 has 2 observations and 8 variables. NOTE: PROCEDURE REG used (Total process time):

NOTE: There were 2 observations read from the data set WORK.VAR_EST2. NOTE: PROCEDURE PRINT used (Total process time): MLOGIC(OLS): %IF condition (ENDOFFILE =1) and ((Probt > &alpha) OR (Probt < 0 )) is FALSE

NOTE: There were 1 observations read from the data set WORK.VAR_EST2. WHERE variable not = 'Intercept'; NOTE: The data set WORK.VAR_EST_2 has 1 observations and 8 variables. NOTE: DATA statement used (Total process time):

NOTE: There were 1 observations read from the data set WORK.HETERO_VAR. NOTE: There were 1 observations read from the data set WORK.VAR_EST_2. NOTE: The data set WORK.HETERO_VAR has 2 observations and 8 variables. NOTE: DATA statement used (Total process time):

NOTE: There were 2 observations read from the data set WORK.HETERO_VAR. NOTE: PROCEDURE PRINT used (Total process time):

MLOGIC(OLS): %DO loop index variable I is now 3; loop will not iterate again.

NOTE: There were 2 observations read from the data set WORK.HETERO_VAR. NOTE: DATA statement used (Total process time):


Back to: Top of message | Previous page | Main SAS-L page