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 (November 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 23 Nov 2004 09:03:04 -0600
Reply-To:     "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject:      Re: Why macro thinks DIM function is a character operator?
Comments: To: Fred <ieaggie2002@gmail.com>
Content-Type: text/plain; charset="us-ascii"

Fred,

Dim() is an open code statement.

%eval(nlag*nef) is giving you there error, because at macro compile time neither nlag nor nef open code vars are defined and can't be used in %eval which is macro code. There are a few other parts of the code that should even if the afore mentioned code was fixed throw the same problem as above.

Try the following You may have to use some %eval statements to get the array elements to resolve right.:

PROC IMPORT DATAFILE = 'test.txt' OUT = TEST DBMS = TAB REPLACE; RUN; PROC SQL NOPRINT; SELECT name INTO:num_list separated BY " " FROM dictionary.columns WHERE libname="WORK" AND memname="TEST" AND TYPE = "num"; %let nef = &sqlobs; Quit;

%LET nlag = 2;

%MACRO LaggedEF; %local i; %local j; DATA LagedEF; SET test; nlag = 2; ARRAY AT{*} &num_list; ARRAY AT1{*} EF1-EF%eval(&nlag*&nef); %DO i=1 %TO nef AT1(&i) = AT(&i); %END; %DO j = 1 %TO &nlag; %DO i=1 %TO &nef; AT1(&j*&nef+i) = lag(AT1((&j-1)*&nef+&i)); %END; %END; RUN; %MEND LaggedEF; %LaggedEF;

Toby

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Fred Sent: Tuesday, November 23, 2004 8:51 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Why macro thinks DIM function is a character operator?

Hi, all I use Macro to do loop computation, which involves the dimension of an existing data set. However, I cannot get it run, since there were messages as below:

PROC IMPORT DATAFILE = 'test.txt' OUT = TEST DBMS = TAB REPLACE; RUN; PROC SQL NOPRINT; SELECT name INTO:num_list separated BY " " FROM dictionary.columns WHERE libname="WORK" AND memname="TEST" AND TYPE = "num"; Quit;

%LET nef=DIM(&num_list);

%MACRO LaggedEF; %local i; %local j; DATA LagedEF; SET test; nlag = 2; ARRAY AT{*} &num_list; ARRAY AT1{*} EF1-EF%eval(nlag*nef); %DO i=1 %TO nef AT1(&i) = AT(&i); %END; %DO j = 1 %TO nlag; %DO i=1 %TO nef; AT1(&j*nef+i) = lag(AT1((&j-1)*nef+&i)); %END; %END; RUN; %MEND LaggedEF; %LaggedEF; ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: nlag*nef ERROR: Missing numeric suffix on a numbered variable list (EF1-EF). WARNING: Defining an array with zero elements. ERROR: The macro LAGGEDEF will stop executing. RUN;

I think "nef" is already a numerical value before the macro definiton. Why macro does not recognize it?

Please give me a hand on this. Thanks for your point.

Fred


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