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
You could always use one of the methods combined with a macro as shown at:
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;
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:
Thanks for all the reply. I will try out both the option.
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.
You could always use one of the methods combined with a macro as shown at:
Thanks. I use fileexist to check if the file exist or not.
Thanks for all your help
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.