BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dwilliams1
Calcite | Level 5

 I want to do the following:

1) Connect to a MS Access database (Successfully done)

2) Create data table of all runs as read from specific table in database (Successfully done)

3) Create data table of the 10 most recent runs (Successfully done)

4) Using proc sql, create a space deliminated list of these runs (Successfully done)

5) Loop over the list and create data tables in the work directory of the most recent 10 runs.  (Fails Miserably)

 

Here's a snippet of the failed part  from the log:

 

319 data _all_; /* Fails miserable */

320 set

321 %do i=1 %to %word_count2(&ParamList);

ERROR: The %DO statement is not valid in open code.

322 &ParamList

323 %end;

ERROR: The %END statement is not valid in open code.

324 ;

325 run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@dwilliams1 wrote:

 I want to do the following:

1) Connect to a MS Access database (Successfully done)

2) Create data table of all runs as read from specific table in database (Successfully done)

3) Create data table of the 10 most recent runs (Successfully done)

4) Using proc sql, create a space deliminated list of these runs (Successfully done)

5) Loop over the list and create data tables in the work directory of the most recent 10 runs.  (Fails Miserably)

 

Here's a snippet of the failed part  from the log:

 

319 data _all_; /* Fails miserable */

320 set

321 %do i=1 %to %word_count2(&ParamList);

ERROR: The %DO statement is not valid in open code.

322 &ParamList

323 %end;

ERROR: The %END statement is not valid in open code.

324 ;

325 run;


The message "ERROR: The %DO statement is not valid in open code." means that you need to create a proper macro using the

%macro to %mend statements to define macro code and then execute the defined macro. Some of the later versions of SAS support

%do in "open code", which means outside of a %macro/%mend code block, but apparently not yours.

 

If your &parmlist contains space delimited proper library.dataset names then the %do is not needed as the set statement accepts multiple data sets. Your code, as written would likely have generated multiple copies of each data set in your list.

Not that the following will make a particularly useful data set it demonstrates use of SET statement with multiple sets:

data work.junk;
   set 
      sashelp.class
      sashelp.cars
   ;
run;

If your PARAMLIST variable looks like proper library dataset names, or all of the sets are in the WORK library then

 

data _all_;
   set 
      &Paramlist
   ;
run;

Should work.

View solution in original post

2 REPLIES 2
dwilliams1
Calcite | Level 5

Attached is the sas code.  Thought it was included initially.

ballardw
Super User

@dwilliams1 wrote:

 I want to do the following:

1) Connect to a MS Access database (Successfully done)

2) Create data table of all runs as read from specific table in database (Successfully done)

3) Create data table of the 10 most recent runs (Successfully done)

4) Using proc sql, create a space deliminated list of these runs (Successfully done)

5) Loop over the list and create data tables in the work directory of the most recent 10 runs.  (Fails Miserably)

 

Here's a snippet of the failed part  from the log:

 

319 data _all_; /* Fails miserable */

320 set

321 %do i=1 %to %word_count2(&ParamList);

ERROR: The %DO statement is not valid in open code.

322 &ParamList

323 %end;

ERROR: The %END statement is not valid in open code.

324 ;

325 run;


The message "ERROR: The %DO statement is not valid in open code." means that you need to create a proper macro using the

%macro to %mend statements to define macro code and then execute the defined macro. Some of the later versions of SAS support

%do in "open code", which means outside of a %macro/%mend code block, but apparently not yours.

 

If your &parmlist contains space delimited proper library.dataset names then the %do is not needed as the set statement accepts multiple data sets. Your code, as written would likely have generated multiple copies of each data set in your list.

Not that the following will make a particularly useful data set it demonstrates use of SET statement with multiple sets:

data work.junk;
   set 
      sashelp.class
      sashelp.cars
   ;
run;

If your PARAMLIST variable looks like proper library dataset names, or all of the sets are in the WORK library then

 

data _all_;
   set 
      &Paramlist
   ;
run;

Should work.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 850 views
  • 0 likes
  • 2 in conversation