Hello,
I inherited a large set of SAS programs and macros that I need to use to calculate a number of indices on environmental data. I think the programs and macros were developed under SAS v7. I currently have v9.4, with IML v14.3, operating under Windows 64-bit. My SAS programming ability is limited and rusty, and I've had no prior experience with IML. The code I inherited calls macros within macros within macros to do such things as variable name manipulation.
The point at which I'm stuck right now is a macro which invokes IML, using other macros to generate the dataset and variable names.
I apologize in advance for the long post -- it shows the errors I get with multiple different attempts at modifying the code. Help will be appreciated! Thank you.
The original code (which does not work) in the calling macro was:
PROC IML;
RESET NONAME;
ERRFLAG=0;
USE &dsn VAR%imlvar(&var);
READ ALL INTO X;
where the dsn name was provided by an earlier call to a different macro and imlvar is another macro, which takes the var variable (provided by an earlier call to yet another macro) and creates a list of indexed variables from other variables, as follows:
%let vari=("%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))");
The value of vari returned is ("s1":"s814"). (Yes, there are 814 numeric fields in this dataset, in addition to numerous other fields.)
The log shows:
MPRINT(TSALL): USE ridsn_
NOTE: Line generated by the invoked macro "IMLVAR".
1 *
-
79
ERROR 79-322: Expecting a {.
MPRINT(IMLVAR): VAR* * ( "s1":
MPRINT(TSALL): "s814");
NOTE: Line generated by the macro variable "VARI".
1 ("s1":"s814")
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
a datetime constant, a missing value, (, (|, ), *, ',', -, =, [, |, }.
ERROR 200-322: The symbol is not recognized and will be ignored.
MPRINT(TSALL): READ ALL INTO X;
ERROR: No data set is currently open for input.
- - - - - - - - - - - - - - - - - - - - - - - - After reading up on IML and changing just one thing at a time, I have modified the code (which still doesn't work) numerous times, some of which follow:
With: PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn) VAR{%imlvar(&var)}; READ ALL INTO X; and %let vari="%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE (ridsn_) VAR{
MPRINT(IMLVAR): * "s1":
NOTE: Line generated by the macro variable "VARI".
1 "s1":"s814"
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
a datetime constant, a missing value, (, (|, ), *, ',', -, =, [, |, }.
ERROR 200-322: The symbol is not recognized and will be ignored.
MPRINT(TSALL): "s814"} READ ALL INTO X;
ERROR: No data set is currently open for input.
- - - - - - - - - - - - - - - - - - - - - - - - With: PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn) VAR(%imlvar(&var)); READ ALL INTO X; and %let vari={"%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))"};
the errors are:
MPRINT(TSALL): USE (ridsn_) VAR(
NOTE: Line generated by the invoked macro "IMLVAR".
1 *
-
79
ERROR 79-322: Expecting a {.
MPRINT(IMLVAR): * * ( "s1":
NOTE 137-205: Line generated by the invoked macro "TSALL".
3 PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn) VAR(%imlvar(&var)); READ ALL INTO X; RESET LOG;
-
22
ERROR 22-322: Syntax error, expecting one of the following: ;, NOBS, VAR, VARIABLES, WHERE.
NOTE: Line generated by the invoked macro "TSALL".
3 PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn) VAR(%imlvar(&var)); READ ALL INTO X; RESET LOG;
-
200
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: Line generated by the macro variable "VARI".
1 ("s1":"s814")
-
79
ERROR 79-322: Expecting a }.
MPRINT(TSALL): "s814") ) READ ALL INTO X;
ERROR: No data set is currently open for input.
- - - - - - - - - - - - - - - - - - - - - - - - With: PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn) VAR{%imlvar(&var)}; READ ALL INTO X; and %let vari="%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE (ridsn_) VAR{
MPRINT(IMLVAR): * * ("s1":
MPRINT(TSALL): "s814")};
NOTE: Line generated by the macro variable "VARI".
1 ("s1":"s814")
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
a datetime constant, a missing value, (, (|, ), *, ',', -, =, [, |, }.
ERROR 200-322: The symbol is not recognized and will be ignored.
MPRINT(TSALL): READ ALL INTO X;
ERROR: No data set is currently open for input.
statement : READ at line 2922 column 75
- - - - - - - - - - - - - - - - - - - - - - - - With: PROC IML; RESET NONAME; ERRFLAG=0; USE (&dsn); READ ALL VAR{%imlvar(&var)} INTO X; and %let vari="%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE (ridsn_);
ERROR: No input file specified.
statement : USE at line 2922 column 43
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.97 seconds
cpu time 0.75 seconds
MPRINT(TSALL): READ ALL VAR{
MPRINT(IMLVAR): * * ("s1":"s814")
MPRINT(TSALL): } INTO X;
- - - - - - - - - - - - - - - - - - - - - - - - With: PROC IML; RESET NONAME; ERRFLAG=0; USE &dsn; READ ALL VAR{%imlvar(&var)} INTO X; and %let vari="%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE ridsn_;
MPRINT(TSALL): READ ALL VAR{
MPRINT(IMLVAR): * * ("s1":
MPRINT(TSALL): "s814")} INTO X;
NOTE: Line generated by the macro variable "VARI".
1 ("s1":"s814")
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
a datetime constant, a missing value, (, (|, ), *, ',', -, =, [, |, }.
ERROR 200-322: The symbol is not recognized and will be ignored.
- - - - - - - - - - - - - - - - - - - - - - - - With: PROC IML; RESET NONAME; ERRFLAG=0; USE &dsn; READ ALL VAR %imlvar(&var) INTO X; and %let vari="%substr(&var,1,%eval(&i-1))":"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE ridsn_;
MPRINT(TSALL): READ ALL VAR
NOTE: Line generated by the invoked macro "IMLVAR".
1 *
-
79
ERROR 79-322: Expecting a {.
MPRINT(IMLVAR): * * ( "s1":
MPRINT(TSALL): "s814") INTO X;
NOTE: Line generated by the invoked macro "TSALL".
3 PROC IML; RESET NONAME; ERRFLAG=0; USE &dsn; READ ALL VAR %imlvar(&var) INTO X; RESET LOG;
-
79
ERROR 79-322: Expecting a }.
NOTE: Line generated by the macro variable "VARI".
1 ("s1":"s814")
-
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
a datetime constant, a missing value, (, (|, ), *, ',', -, =, [, |, }.
ERROR 200-322: The symbol is not recognized and will be ignored.
- - - - - - - - - - - - - - - - - - - - - - - - With:
PROC IML; RESET NONAME; ERRFLAG=0; USE &dsn; READ ALL VAR{%imlvar(&var)} INTO X; and %let vari="%substr(&var,1,%eval(&i-1))"-"%substr(&var,%eval(&i+1),%eval(%length(&var)-&i))";
the errors are:
MPRINT(TSALL): USE ridsn_;
MPRINT(TSALL): READ ALL VAR{
MPRINT(IMLVAR): * * * "s1"-"s814"
MPRINT(TSALL): } INTO X;
NOTE: Line generated by the macro variable "VARI".
1 "s1"-"s814"
------
22
76
ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, a missing value.
ERROR 76-322: Syntax error, statement will be ignored.
... View more