Search code examples
sassas-macro

How can I use data format DDMMYYDw. in Proc Import SAS MACRO


so I have a code like this

%let fdate=%sysfunc(today());
%put %sysfunc(putn(&fdate,MMDDYYD10.));
%let ydate=%eval(&fdate-1);
%put %sysfunc(putn(&ydate,MMDDYYD10.));

AND it seems working

127  %let fdate=%sysfunc(today());
128  %put %sysfunc(putn(&fdate,MMDDYYD10.));
SYMBOLGEN:  Macro variable FDATE resolves to 22152
08-25-2020
129  %let ydate=%eval(&fdate-1);
SYMBOLGEN:  Macro variable FDATE resolves to 22152
130  %put %sysfunc(putn(&ydate,MMDDYYD10.));
SYMBOLGEN:  Macro variable YDATE resolves to 22151
08-24-2020

but I am using like this.

proc import datafile = "S:csse_covid_19_daily_reports\&ydate..csv"
 out = T0824
 dbms = CSV
 REPLACE;

 GUESSINGROWS=100000;
 
run;

The error message is showing like this.

\csse_covid_19_daily_reports\22151.csv.
ERROR: Import unsuccessful.  See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds

They converted back to 22151.

I have a file like this

enter image description here

so to pull this file in proc import, I want format like 8-24-2020. so I can get data from CSV to sas.

How can I fix the code?

Thanks


Solution

  • You need to use the same variable. In your testing you're using %SYSFUNC() but in your code you're not, so you're not comparing the same thing really.

    Change your code to be:

     "S:csse_covid_19_daily_reports\%sysfunc(putn(&ydate.,MMDDYYD10.)).csv"
    

    Or change your macro variable to be formatted. If you're using it in multiple locations then use %SYSFUNC() to control the display in different sitautions as warranted.