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 08:12:05 -0700
Reply-To:   Lund Peter <Peter.Lund@OFM.WA.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Lund Peter <Peter.Lund@OFM.WA.GOV>
Subject:   Re: PROBLEM WITH MACROVARIABLES
Comments:   To: Josune Gallego Merino <ccbgamej@SI.EHU.ES>
Content-Type:   text/plain; charset="us-ascii"

Josune- If what you're really trying to do is create macro variables (MBETA0-MBETAn) whose values match corresponding datastep variables (BETA0-BETAn) you made it much more difficult than it needs to be. Try something like:

%let NumVar = 5; data _null_; beta0 = -7.687; * intercept; beta1 = -0.0251; * age; beta2 = 1.8990; * sex; beta3 = 1.7412; * chestp1; beta4 = 0.7849; * chestp2;

array beta(&NumVar) beta0-beta%eval(&Numvar-1);

do i = 1 to &NumVar; call symput('mbeta'||left(put(i,2.)),put(beta(i),7.4)); end; run;

%put &Mbeta0; %put &Mbeta1; %put &Mbeta2; %put &Mbeta3; %put &Mbeta4;

This should give you what you need.

HTH- Pete Lund WA State Office of Financial Management peter.lund@ofm.wa.gov

---------- From: Josune Gallego Merino[SMTP:ccbgamej@SI.EHU.ES] Sent: Friday, April 18, 1997 5:12 AM To: Multiple recipients of list SAS-L Subject: PROBLEM WITH MACROVARIABLES

Hello, SAS-Lers!

I 've got a problem. I want to give to some macrovariables the values of some variables in order to use them later. I have tried with the code below but the value of the macrovariable is always the same, the name of the variable not its value. I want to know what is wrong with the code.

Thanks in advance,

Josune Gallego e-mail: ccbgamej@si.ehu.es

******* program *******

%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