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 (April 1997, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 18 Apr 1997 11:42:39 PDT
Reply-To:     TWB2%Rates%FAR@GO50.COMP.PGE.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         TWB2%Rates%FAR@GO50.COMP.PGE.COM
Subject:      Re: PROBLEM WITH MACROVARIABLES
Comments: To: ccbgamej@SI.EHU.ES

Josune, The posted code has a fatal flaw as well as an artistic error. The fatal flaw is that, unless a macro variable is explicitly declared GLOBAL, it is only available in the macro which defines it (and macros nested inside that macro). Your macro variables defined in macro BESTV are not available in macro MEJORV. You can fix this with a %GLOBAL statement. The macro variables defined in open code (&mbvara, etc.) are available in all macros.

The artistic error is that you really do not need any macro syntax in the BESTV macro other than the macro variables in the ARRAY statements. You could avoid %do and %eval and use regular data step DO loops.

Hmm, you also seem to have more %end's than you have %do's. That will usually cause problems.

Tim Berryhill - Contract Programmer and General Wizard TWB2@PGE.COM or http://www.aartwolf.com/twb.html Frequently at Pacific Gas & Electric Co., San Francisco The correlation coefficient between their views and my postings is slightly less than 0 ----------------------[Reply - Original Message]---------------------- %let n = 5; * number of variables;

%let mbvara = mbeta; %let bvara = beta; %LET BBVARA = BBETA;

%MACRO BESTV( DATAIN = ); /* CREATES THE MACROVARIABLES MBETA0 - MBETA20 WITH THE VALUES OF THE VARIABLES BETA0 - BETA20 */

DATA &DATAI;

array bvar[&n] &bvara.0 - &bvara. %eval(&n -1);

ARRAY BVARC[&N] $8.4 &BBVARA.0 - &BBVARA.%eval(&n -1);

array bvar[&n] &bvara.0 - &bvara. %eval(&n -1);

* variables; beta0 = -7.687; * intercept; beta1 = -0.0251; * age; beta2 = 1.8990; * sex; beta3 = 1.7412; * chestp1; beta4 = 0.7849; * chestp2;

%DO H = 0 %TO %eval(&n-1); * NUMBER OF VARIABLES;

BVARC[%eval(&h+1)] = PUT(BVAR[%eval(&h+1)],8.4) ;* CONVERTS THE VALUE TO CHAR; PUT 'VALOR DE BVARC ' BVARC[%eval(&h+1)]; * PRINTS THE VALUE OF THE VAR; CALL SYMPUT("&MBVARA.&h",BVARC[%eval(&h+1)]);* ASSIGNS IT TO THE MACROVAR?;

%END;

%END;

PROC PRINT;

%MEND;

DATA _NULL_;

%MEJORV( DATAI = &FLOG, MEJOR = VALMIN);

PUT "VALUE OF THE MACROVAR &MBVARA.1 IS &&MBVARA.1 "; * PRINTS ONLY THE NAME OF THE VARIABLE, IT SHOULD BE THE VALUE OF THE VAR; PUT "VALUE OF THE MACROVAR &&MBVARA.1 IS &&&MBVARA.1 ";

PROC PRINT; RUN;

=====================================================================


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