10-29-2017 10:20 PM
May I know what happened to code 1? I can import perfectly with code 2. May I know how to make code 1 works? Thanks.
%if %sysfunc(exist(&dsn)) %then %do;
PROC IMPORT OUT=sales
PROC IMPORT OUT=SALES
10-29-2017 10:41 PM
As you can see from the macro call, Code #1 expects to receive a quoted path to a file. The macro checks to see whether that file actually exists. If it does, it imports the file into a SAS data set named SALES. If the file doesn't exist, the macro creates a SAS data set named SALES, holding just one observation where ID is blank and AMOUNT is 0.
10-30-2017 03:01 AM
exist() is a function that checks for the existence of a SAS dataset, so it needs an argument that describes such (LIBNAME.DATASET). Since you want to check for an external (non-SAS) file, you need to use the fexist() function.