Suspect this is just a typo for the example, but in your proc sql step you select a variable called YEAR but in the prior dataset the variable is called TERM.
Fixing this and changing QSCAN to SCAN allows the code to work correctly.
data yearlist;
input term;
datalines;
1998
1999
2000
2001
2002
2003
2004
2005
2006
;
run;
proc sql;
select term into :Yearlist separated by ' ' from yearlist;
quit;
%macro classes;
%do i=1 %to %sysfunc(countw(&Yearlist, %str( )));
%let yearcounter = %scan(&Yearlist, &i, %str( ));
data work.year_&yearcounter;
set sashelp.class;
run;
%end;
%mend;
%classes;
Note that if your years are consecutive and you know the start/end you could just use those in the loop instead of creating a macro variable list.
%do yr=&startYear %to &endYear;
data year_&yr.;
....
run;
%end;
@sasuser1444 wrote:
I've got a pretty simple macro to take values from a list of strings and use them to name datasets. I use the variable "yearcounter" represent the actual value of where we are in the list. When I try to create a dataset name with it, I get the error
NOTE: Line generated by the macro variable "YEARCOUNTER".
work.year_1998
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
So it's placing the year in the right spot, but it's not interpreting the whole line of code. If I replace the [yearcounter] variable with [i], it runs fine with no problems, but then I get datasets with names like year_1, year_2, and so forth. Any idea what's going on?
data yearlist;
input term;
datalines;
1998
1999
2000
2001
2002
2003
2004
2005
2006;
run;
proc sql;
select year into :Yearlist separated by ' '
from yearlist;
quit;
%macro classes;
%do i = 1 %to %sysfunc(countw(&Yearlist,%str( )));
%let yearcounter = %qscan(&Yearlist,&i,%str( ));
data work.year_&yearcounter;
set otherdataset;
[dataset operations]
run;
%end;
%mend;
%classes;
... View more