BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pants4
Calcite | Level 5

I'm trying to import a .xls file that is posted daily as part of an automated procedure.  A sample path is shown below:

https://www.xyzqrs.com/Reports/20120730_ex.xls

The following code works:

filename website http "https://www.xyzqrs.com/Reports/20120730_ex.xls" debug;

data file;
  n=-1;
  infile website nbyte=n length=len;
  input;
  file "20120730_ex.xls";
  put _infile_ $varying32767. len;
  run;

PROC IMPORT OUT=WORK.excelfile DATAFILE="20120730_ex.xls" DBMS=EXCEL REPLACE;
GETNAMES=NO;
MIXED=YES;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

I want to somehow use a macro variable or some other method to edit red text above, so everyday when this runs, it grabs the most recent file. I've tried to use macro variables to pass in the date, but it doesn't read it correctly in the program. I've tried researching the answer online, but no luck up to this point. Any help is appreciated...Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I can't test this at the moment, but think it is either correct or close enough that you should be able to get it to work:

%let fname=%sysfunc(putn(%sysfunc(today()),yymmddN8.));
filename website http "https://www.xyzqrs.com/Reports/&fname._ex.xls" debug;

data file;
  n=-1;
  infile website nbyte=n length=len;
  input;
  file "&fname._ex.xls";
  put _infile_ $varying32767. len;
  run;

PROC IMPORT OUT=WORK.excelfile DATAFILE="&fname._ex.xls" DBMS=EXCEL REPLACE;
GETNAMES=NO;
MIXED=YES;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

I can't test this at the moment, but think it is either correct or close enough that you should be able to get it to work:

%let fname=%sysfunc(putn(%sysfunc(today()),yymmddN8.));
filename website http "https://www.xyzqrs.com/Reports/&fname._ex.xls" debug;

data file;
  n=-1;
  infile website nbyte=n length=len;
  input;
  file "&fname._ex.xls";
  put _infile_ $varying32767. len;
  run;

PROC IMPORT OUT=WORK.excelfile DATAFILE="&fname._ex.xls" DBMS=EXCEL REPLACE;
GETNAMES=NO;
MIXED=YES;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;

pants4
Calcite | Level 5

Worked like a charm. Thanks for the quick reply and fix

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 697 views
  • 0 likes
  • 2 in conversation