DATA Step, Macro, Functions and more

Create Empty Data File

Accepted Solution Solved
Reply
SAS Employee
Posts: 73
Accepted Solution

Create Empty Data File

I have program that imports the source data into sas dataset daily.  Is it possible in SAS to create empty data file and export it to some location when the actual source file is not found ?

Thanks


Accepted Solutions
Solution
‎09-10-2011 08:44 PM
PROC Star
Posts: 7,467

Create Empty Data File

You could always use one of the methods combined with a macro as shown at:

http://support.sas.com/kb/24/670.html

View solution in original post


All Replies
PROC Star
Posts: 7,467

Create Empty Data File

Of course!  You can use either a datastep or proc sql and just assign a libname to the directory where you want it to exist.  e.g.,

DATA CORP.want;

   SET CORP.have;

   STOP;

RUN;

PROC SQL noprint;

  CREATE TABLE CORP.want

    LIKE CORP.have

  ;

quit;

Respected Advisor
Posts: 3,799

Re: Create Empty Data File

Do you want a data set with variables and zero obs or zero variables and zero obs?  If you want variables and zero obs do you have a data set where the variable attributes can be copied from?  For 0:0 you can use.

2128 data zero;

2129 stop;

2130 run;

NOTE: The data set WORK.ZERO has 0 observations and 0 variables.



The 0:0 data could be used in a program to add obs to an existing data set.  Where nothing happens unless the 0:0 is not 0:0 but actually has variables and observations.

2136 data class;

2137 set sashelp.class;

2138 run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

NOTE: The data set WORK.CLASS has 19 observations and 5 variables.

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

2139 data class;

2140 if 0 then modify class;

2141 set zero;

2142 output;

2143 run;

NOTE: The data set WORK.CLASS has been updated. There were 0 observations rewritten, 0

observations added and 0 observations deleted.

NOTE: There were 0 observations read from the data set WORK.ZERO.

So as you see it depends on what you have and what you want. :smileygrin:

SAS Employee
Posts: 73

Create Empty Data File

Posted in reply to data_null__

Thanks for all the reply.  I will try out both the option.

SAS Employee
Posts: 73

Create Empty Data File

Posted in reply to data_null__

I need to create empty table with variables.  Also, is it possible to check to see if the file exist if it does then use the original file as main source if it does not create empty data set to avoid the error.

Thanks in advance.

Solution
‎09-10-2011 08:44 PM
PROC Star
Posts: 7,467

Create Empty Data File

You could always use one of the methods combined with a macro as shown at:

http://support.sas.com/kb/24/670.html

SAS Employee
Posts: 73

Create Empty Data File

Thanks.  I use fileexist to check if the file exist or not.

Thanks for all your help

🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 9089 views
  • 0 likes
  • 3 in conversation