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 (June 2005, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 3 Jun 2005 19:50:45 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: macro variable will not evaluate as numeric
Comments: To: ryandiver@GMAIL.COM
In-Reply-To:  <1117826859.487006.191420@g14g2000cwa.googlegroups.com>
Content-Type: text/plain; format=flowed

Ryan,

You have your macro compile and execute time mixed up with your open code datastep compile and execute time.

%IF &INT=&I AND &MAIN=&J %THEN %STR(&INTDES.&I.&MAINDES.&J. = 1;); %ELSE %STR(&INTDES.&I.&MAINDES.&J. = 0;);

Here &INT will always have a value of 'CURRMULT' and &I will always be a number between 1 and 2 (in the case of your example.

&main will always have a value of 'LFDAIRGC' and &J will always have a value between 1 and 5. Since neither &INT=&I or &MAIN=&J will ever be true it writes "&INTDES.&I.&MAINDES.&J. = 0;" this out and that gets compiled and executed at SAS open code compile and execute, meaning that you will always get zero's.

Remember that macro code 99% of the time only writes the open SAS code.

Toby Dunn

From: Ryan Diver <ryandiver@GMAIL.COM> Reply-To: Ryan Diver <ryandiver@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: macro variable will not evaluate as numeric Date: Fri, 3 Jun 2005 12:27:39 -0700

I'm new to macro coding and I'm trying to create a macro that will give me a 1/0 variable for every combination of two variables. The macro runs with out error messages, but all of the variables only have values of 0. It doesn't look like the condition for assigning a 1 is being met, but I can't figure out why. Any suggestions on the following code would be helpful.

%MACRO INTX(MAIN=&MAIN,MAINCAT=&MAIN,MAINDES=&MAINDES, INT=&INT,INTCAT=&INTCAT,INTDES=&INTDES);

DATA TEMP; SET ONE; **CREATE INTERACTION TERMS***; %DO I=1 %TO &INTCAT.; %DO J=1 %TO &MAINCAT.; %IF &INT=&I AND &MAIN=&J %THEN %STR(&INTDES.&I.&MAINDES.&J. = 1;); %ELSE %STR(&INTDES.&I.&MAINDES.&J. = 0;); %END; %END;

RUN;

%MEND INTX;

%INTX(MAIN=LFDAIRGC,MAINCAT=5,MAINDES=LFD, INT=CURRMULT,INTCAT=2,INTDES=MVT)

In this case LFDAIRGC is a numeric variable with values 1 to 5 and CURRMULT is a numeric variable with values 1 to 2.


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