Alex
Alex

Reputation: 19803

Delete SAS dataset

I have several datasets that I would like to delete after my SAS procedure has finished. I am using this statement:

proc datasets lib=temp;
    delete xtemp2&sysparm trades&sysparm tickers&sysparm;
quit;
run;

where

&sysparm evaluates to a number and temp to a libname. However, I receive the following errors in the log file:

142             delete xtemp2&sysparm trades&sysparm tickers&sysparm;
            ______
            180
ERROR 180-322: Statement is not valid or it is used out of proper order.

Anyone know the issue?

EDIT:

Here is some more of the log file to address the answer:
NOTE: "OUT_CSV" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.27 seconds
      cpu time            0.12 seconds


142             delete xtemp2&sysparm trades&sysparm tickers&sysparm;
        ______
        180
ERROR 180-322: Statement is not valid or it is used out of proper order.

Here is the code immediately prior to the proc:

proc export data=temp.xtemp2&sysparm outfile=out_csv dbms=csv replace;
run;

proc datasets lib=temp;
    delete xtemp2&sysparm trades&sysparm tickers&sysparm;
quit;
run;

Upvotes: 3

Views: 15431

Answers (6)

Mohammed Ismail
Mohammed Ismail

Reputation: 37

Most of the developers have answered this question very well. However I would like to put additional Information.

Actually, the Run or Quit step is optional. U put it to indicate the completion of the Data Step ua looking into.

SAS procedure steps terminate when one of these is encountered:

  • the beginning of the "next" DATA or PROC step
  • an explicit step boundary is reached (either RUN; or QUIT; as appropriate)
  • if you are submitting a job in "batch" mode (such as in a SYSIN DD * on the mainframe) and the end of the input file is encountered (which would be */ on the mainframe).

Further to this you can refer the below link ... https://communities.sas.com/t5/Base-SAS-Programming/Why-use-QUIT-with-proc-SQL/td-p/97992

Upvotes: 0

stallingOne
stallingOne

Reputation: 4006

I'm using this

%macro drop / parmbuff store source
    DES="drop(table1,...tableN): Drops tables if they exists";
    %let num=1;
    %let stepneeded=0;
    %let stepstarted=0;
    %let dsname=%scan(&syspbuff,&num,',()');
    %do %while(&dsname ne); 
        %if %sysfunc(exist(&dsname)) %then %do;
            %let stepneeded=1;
            %if (&stepstarted eq 0) %then %do;
                proc sql;
                %let stepstarted=1;
            %end;
                drop table &dsname;
        %end;
        %if %sysfunc(exist(&dsname,view)) %then %do;
            %let stepneeded=1;
            %if (&stepstarted eq 0) %then %do;
                proc sql;
                %let stepstarted=1;
            %end;
                drop view &dsname;
        %end;
        %let num=%eval(&num+1);
        %let dsname=%scan(&syspbuff,&num,',()');
    %end;
    %if &stepstarted %then %do;
        quit;
    %end;
%mend drop;

then just %drop(work.mytable);

Upvotes: 0

RosaryGuy
RosaryGuy

Reputation: 31

You can also use the following which runs fast but has been considered to be a 'deprecated' procedure:

 Proc Delete Data = Temp._all_;    *This will delete all datasets in temp;
 run;

Upvotes: 1

BellevueBob
BellevueBob

Reputation: 9618

Looking at your log, it seems that you are not executing your PROC DATASETS statement, such that the `delete' statement is showing up in open code. As Joe said, you probably have a stray character in your code. If not, please repost with more infor from your SAS log. Include everything from the previous step boundary.

Upvotes: 1

Def_Os
Def_Os

Reputation: 5457

I suspect SAS has trouble parsing whatever you brought into your &sysparm macro valuable. Did you check its value?

Upvotes: 0

Joe
Joe

Reputation: 63424

There's nothing explicitly wrong with your code, except that last RUN is not needed (QUIT is sufficient for PROC DATASETS). I created datasets with those parameters and the code as provided worked fine. Often that error comes when you have something just before the proc statement that causes the proc statement not to compile. For example:

*
proc datasets lib=temp;
    delete xtemp2&sysparm trades&sysparm tickers&sysparm;
quit;

would cause the error message you provided, along with almost anything else that was not properly ended (although most other errors of that nature would cause a second error message with the preceding statement).

Upvotes: 8

Related Questions