Hi can you help.
My sas macro is not resolving a value but i'm not sure why. Can you have a look?
error log attached.
Regards
Rob
OPTIONS symbolgen mlogic mprint ;
%let paramfile = \\Essentsvr\saas\Development RR\CIRT-ACIS Parameter File 20180912 (TG - ACIS working).xlsm;
%macro getinfile(fileloc, tab);
PROC IMPORT OUT=&tab
DATAFILE= "&fileloc"
DBMS=EXCEL REPLACE ;
GETNAMES=YES;
Sheet="&tab";
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;
%mend ;
%macro assignmacros(tabdseti,type);
%PUT "Running Macro: assignmacros (tabdseti=&tabdseti.,type=&type.)";
*%global nvars nobs;
%if &type ne ACIS_B %then
%do;
%getinfile(¶mfile, &tabdseti) ;
%let tabdsid=%sysfunc(open(&tabdseti));
%let nvars=%sysfunc(attrn(&tabdsid,nvars));
%let nobs=%sysfunc(attrn(&tabdsid,nlobs));
* var1-varn will define the field names;
%do i=1 %to &nvars;
%let var&i=%sysfunc(varname(&tabdsid,&i));
%end;
%let close=%sysfunc(close(&tabdsid));
* for example if reading tab "Input Fields CS CIRT Setup Data" for var1=reference this will create a macro name reference1-reference(nobs) var2 field1-field(nobs) etc;
data _null_;
set &tabdseti;
%do i=1 %to &nvars;
%do j=1 %to &nobs;
%global &&var&i..&j;
%end;
%end;
run;
proc sql noprint;
%do i=1 %to &nvars;
select &&var&i into :&&var&i..1-:&&var&i..&nobs
from &tabdseti;
%end;
quit;
* this bit assigns the value to the macro variables so that the program knows that say CS01_field=poolid CS_01_format=$16. etc;
%do i=1 %to &nobs;
%global &&&var1.&i &&&var2.&i;
%let &&&var1.&i=&&&var2.&i;
/*%if %length(&&&var3.&i)>0 %then %do; %global &&&var3.&i; %let &&var2.&i=&&&var3.&i; %end;
%if %length(&&&var4.&i)>0 %then %do; %global &&&var4.&i; %let &&var3.&i=&&&var4.&i; %end;
%if %length(&&&var5.&i)>0 %then %do; %global &&&var5.&i; %let &&var4.&i=&&&var5.&i; %end;*/
%end;
%end;
%else
%do nextinp=0 %to 3;
%let k = %scan(20 50 51, &nextinp);
%getinfile(¶mfile, &tabdseti.&k) ;
%let tabdsid&k=%sysfunc(open(&tabdseti&k));
%let nvars_RT&k=%sysfunc(attrn(&&tabdsid&k,nvars));
%let nobs_RT&k=%sysfunc(attrn(&&tabdsid&k,nlobs));
* var1-varn will define the field names;
%do i=1 %to &&nvars_RT&k;
%let var&k&i=%sysfunc(varname(&&tabdsid&k,&i));
%end;
%end%
%let close=%sysfunc(close(&&tabdsid&k));
%mend;
%assignmacros(Pre_AS_Inpt_Flds_ACIS_SUp_RT,ACIS_B);
Your problem starts with this message:
SYMBOLGEN: Macro variable NEXTINP resolves to 0 WARNING: Argument 2 to macro function %SCAN is out of range.
You start your loop for variable k from 0. It should be 1. This is how %scan() works. So try this:
%do nextinp=1 %to 3;
%let k = %scan(20 50 51, &nextinp);
and take it from there.
Hope this helps,
- Jan.
Hey thanks for your speedy reply.
It helps but still getting the below.
Its still not resolving
&&nvars_RT&k
Regards
Rob
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable K resolves to 20
SYMBOLGEN: Macro variable TABDSID20 resolves to 0
WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is
out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
result of the operations have been set to a missing value.
SYMBOLGEN: Macro variable K resolves to 20
MLOGIC(ASSIGNMACROS): %LET (variable name is NOBS_RT20)
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable K resolves to 20
SYMBOLGEN: Macro variable TABDSID20 resolves to 0
WARNING: Argument 1 to function ATTRN referenced by the %SYSFUNC or %QSYSFUNC macro function is
out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
result of the operations have been set to a missing value.
MPRINT(ASSIGNMACROS): * var1-varn will define the field names;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable K resolves to 20
SYMBOLGEN: Macro variable NVARS_RT20 resolves to .
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &&nvars_RT&k
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro ASSIGNMACROS will stop executing.
MLOGIC(ASSIGNMACROS): Ending execution.
There is an earlier warning that no value supplied to attrn, so there is where your problems start. As for debugging it, thats up to you, put options symbolgen mlogic mprint; on and read all of what is generated in the log.
You are doing everything that I would consider to be sub-optional though.
First: xlsm - file type of compiled macro enabled workbook. Why? Its not portable and Excel is a dreadful format to use for data.
Proc import - this is a guessing procedure, add this to the bad file format and there is no telling what data you will end up with. Fix your whole import process to be robust and repeatable, this will eliminate most of any other errors you will get.
Assigning global macro variables within macros. This can lead to very hard to debug errors across the system (depends of course on your setup) as global affects the whole session. Its rarely a good idea to be changing macro variables which affect the whole system in parts of code.
You then appear to read some sort of tab delimited file and create loads of macro variables from that. Use the right tool, datasets to store data. Macro is nothing but a find/replace system. Any time you start getting more than one & in your code, you can 100% guarentee there is a better method to do what you want.
As a general note, always put the dot after macro variables, this can lead to errors even if most of the time you get away with it, its good practice to always do it.
Provide some test data in the form of a datastep and what you want out for more specific information.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.