Help using Base SAS procedures

do loop sas

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 79
Accepted Solution

do loop sas

I am not sure what I am doing wrong here, its a very simple example just for me to understand why its giving me an error

%let nc = 1;

data _null_;
do nc = 1 to 10;

proc datasets lib=work kill memtype=data;

end;
run;

This gives me the following error

end;

        ---

        180

ERROR 180-322: Statement is not valid or it is used out of proper order

Thank you for your help!


Accepted Solutions
Solution
‎05-03-2012 03:10 PM
Occasional Contributor
Posts: 14

Re: do loop sas

How about this instead:  It will iterate 10 times, whatever you set amax too.

%let amax = 10;

%macro testme;
  %do i = 1 %to &amax;
      proc datasets lib=work kill memtype=data;
      quit;
  %end;
%mend testme;

%testme ;

:smileygrin:

View solution in original post


All Replies
Trusted Advisor
Posts: 2,113

Re: do loop sas

The Do-End combination is part of a DATA step, you can't have PROC's within DATA steps.  What SAS sees is the END; statement included in the PROC and it is not a valid statement for PROC DATASETS.  That is the reason for the error message.

When I run your code, I also get the error message

ERROR 117-185: There was 1 unclosed DO block.

indicating that SAS did not see the END-statement in the DATA step.

However, the larger problem is that you are probably just getting into macro programming and want to actually execute the PROC 10 times.  I would recommend that you read the chapter on macro language programming and go through the examples there before you launch out on your own.

Doc Muhlbaier

Duke

Solution
‎05-03-2012 03:10 PM
Occasional Contributor
Posts: 14

Re: do loop sas

How about this instead:  It will iterate 10 times, whatever you set amax too.

%let amax = 10;

%macro testme;
  %do i = 1 %to &amax;
      proc datasets lib=work kill memtype=data;
      quit;
  %end;
%mend testme;

%testme ;

:smileygrin:

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 516 views
  • 3 likes
  • 3 in conversation