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 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 26 Apr 2004 08:55:01 -0400
Reply-To:     Ed Heaton <EdHeaton@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ed Heaton <EdHeaton@WESTAT.COM>
Subject:      Re: error in a macro
Comments: To: Mayukh Dass <dass@UGA.EDU>
Content-Type: text/plain


The SAS macro facility is used to write SAS code. It's use is valuable when your SAS code needs to be dynamically generated. You don't have such a need in your code below. Macro variables can also be valuable for initializing parameters at the start of your code. This is good programming practice. Your %LET statements are good examples. I would even add another called something like &infilePath.

%let course_no = 5 ; %let attr_no = 3 ; %let vars_no = %eval( &course_no * &attr_no ) ; %let infilePath = C:\Documents and Settings\Mayukh Dass\My Documents\iFolder\6360 ; %let fileName = rec3.dat ;

Now, for your DATA step code. Use your macro variables, but forget the macro loop. Remember, use macro to write SAS code when a small amount of macro code will write large amounts of SAS code or when you need to write dynamic SAS code.

Data two ; InFile "&infilePath\&filename" missOver ; Input ( name desc1 - desc&vars_no )($) ; Array desc [&vars_no] ; Do n=&attr_no to dim(desc) by &attr_no ; totHr = totHr + input( desc[n] , 1. ) ; End ; Run ;

This code is untested.


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

-----Original Message----- From: Mayukh Dass [mailto:dass@UGA.EDU] Sent: Sunday, April 25, 2004 11:43 PM To: SAS-L@LISTSERV.UGA.EDU Subject: error in a macro


I am trying to calculate sum of variables desc3, desc6, desc9, desc12, desc15. Initially, these variables are read as strings.

%let course_no=5; %let attr_no=3; %let vars_no=%eval(&course_no*&attr_no); %let filename=rec3.dat;

data two; infile "C:\Documents and Settings\Mayukh Dass\My Documents\iFolder\6360\&filename" missover; input name$ (desc1-desc&vars_no)($); do n=3 to 16 by 3; tothr=tothr+input(&&desc&n, 1.); end; run; proc print; run;

but the following error is occuring:

134 %let course_no=5; 135 %let attr_no=3; 136 %let vars_no=%eval(&course_no*&attr_no); 137 %let filename=rec3.dat; 138 139 data two; 140 infile "C:\Documents and Settings\Mayukh Dass\My Documents\iFolder\6360\&filename" missover 140! ; 141 input name$ (desc1-desc&vars_no)($); 142 do n=3 to 16 by 3; 143 tothr=tothr+input(&&desc&n, 1.); WARNING: Apparent symbolic reference N not resolved. NOTE: Line generated by the macro variable "N". 1 &desc& - 22 WARNING: Apparent symbolic reference DESC not resolved. WARNING: Apparent symbolic reference N not resolved. ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT.

144 end; 145 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). <no line/column information available> NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 1:6 NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.TWO may be incomplete. When this step was stopped there were 0 observations and 18 variables. WARNING: Data set WORK.TWO was not replaced because this step was stopped. NOTE: DATA statement used: real time 0.01 seconds cpu time 0.00 seconds

146 proc print; 147 run;

NOTE: No observations in data set WORK.TWO. NOTE: PROCEDURE PRINT used: real time 0.01 seconds cpu time 0.00 seconds

Would you please tell me where I am making the mistake?

Regards, Mayukh

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