LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 18 Jul 2005 18:22:37 -0700
Reply-To:     Rob_W <weyrauch_r@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Rob_W <weyrauch_r@YAHOO.COM>
Organization: http://groups.google.com
Subject:      Create, append or delete datasets in macro
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset="iso-8859-1"

Goal: I need to check if a dataset exists (eg: FileA), if it does then I need to append another file to it (eg: FileB).

If FileA does not exist, then I need to create it based on the data in FileB.

Question: Using a macro called from a datastep, how can you check if a file exists, and then conditionally either append or create the dataset as needed?

Code: The following is the code that obviously does not work. I included it here in hopes that it clarify what I am trying to accomplish. Thanks for the input....

************************ ************************

%MACRO AppendTempDs(CheckFile=, CurrentFile=) ;

%IF %SYSFUNC(FILEEXIST( &CheckFile )) %THEN %DO; PROC APPEND BASE=&CheckFile DATA=&CurrentFile ; RUN; %END; %ELSE %DO; DATA &CheckFile ; SET &CurrentFile; RUN ; %END;

PROC DATASETS ; DELETE &CurrentFile ; RUN;

%MEND AppendTempDs ;

**************************; ** Sample call to macro **; **************************;

DATA;

%AppendTempDs(CheckFile="FileA" , CurrentFile="FileB" ) ;

RUN;

************************ ************************


Back to: Top of message | Previous page | Main SAS-L page