If you define the VAR variable with a length of $30, it means that each value is stored on 30 characters. Even if the real value is shorter, blanks are added are the right of the value, so that the total length is 30 for each value, blanks included.
When you create the NAMES macro-variable, in the SQL query, you concatenate strings that are 30 characters long (in fact, 31, since there is an additional space added because of the SEPARATED BY " " option). DuRi, in his initial post, says he has 7,000 datasets : so here, the NAMES macro-variables will have to contain 7,000 * 31 characters = 217,000 characters (correct ?). Which is a lot more that any macro-variable can contain (see
http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a002293823.htm ; no more than 65,534 characters).
Olivier