Hi:
About this piece of your question:
[pre]
data _null_;
do i = 1 to &nTabelas;
proc sql print;
select name into :nomesColunas separated by ' '
from DDS..&tabelas;
end;
run;
[/pre]
You cannot have a PROC SQL step inside a DATA step program. You must investigate other ways (such as a macro program which contains your PROC SQL code inside a macro do loop or a DATA step program which performs a CALL EXECUTE).
In general, SAS programs are composed of PROCEDURE steps and DATA steps. It is not appropriate to put an SQL step inside a DATA step in open code. When you got the error message about having an unclosed DO block, that was SAS trying to show you that the beginning of the PROC SQL step caused the compiler to detect that the DO block in the DATA step program had not "finished":
[pre]
12 data _null_;
13 do i = 1 to &nTabelas;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
14 proc sql print;
-
117
ERROR 117-185: There was 1 unclosed DO block.
15 select name into :nC separated by ' '
16 from sashelp.class;
17 end;
---
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
18 run;
NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.51 seconds
cpu time 0.09 seconds
[/pre]
If you DO set up code to execute (via CALL EXECUTE), it executes AFTER the data step has finished building the appropriate statements.
I usually recommend a more conservative approach which would be to start with a macro program and understand how that works first before jumping into CALL EXECUTE.
The macro facility documentation is quite thorough and contains examples of writing programs that execute based on iterations through a macro %DO loop (as opposed to a data step DO loop).
This paper is also a good resource for people who are just learning about macro processing:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
cynthia