Good day all,
I am facing the problem with importing excel file through macros.
the excel name is DATAExport 2015-05-04-12-18-52
the file is coming every week monday. so i created macro for this.
%LET TODAY1=%SYSFUNC(TODAY(),DATE9.);
%LET LAST_WEEK=%SYSFUNC(INTNX(WEEK,"&TODAY1."D,-1,B),DATE9.);
%LET LAST_WEEK_MONDAY=%SYSFUNC(INTNX(DAYS,"&LAST_WEEK."D,1),YYMMDDD10.);
here I didn't create macro for time. The file contains time at the end.
Up to DATAExport 2015-05-04 this i can automate using macro.
proc import datafile="D:\emp\DATAExport &LAST_WEEK_MONDAY..xls"
but what my requirement is what ever the time it is consider only Date. and ignore time.
How to import this excel file. the time is changes from file to file. So i can't importing it successfully.
Any help would be greatly appreciated.
Well that's too bad. The LIBNAME statement is not as smart as the INFILE statement.
%LET TODAY1=%SYSFUNC(TODAY(),DATE9.);
%LET LAST_WEEK_MONDAY=%SYSFUNC(INTNX(WEEK.2,"&TODAY1."D,-1,B),YYMMDDD10.);
%put &=TODAY1 &=&LAST_WEEK_MONDAY;
data _null_;
length filename $256;
infile "D:\emp\DATAExport &LAST_WEEK_MONDAY*.xls" filename=filename obs=1;
input @;
call symputx('FILENAME',filename);
run;
proc import datafile="&filename" ....
Since you can build the name up to the date, make a directory listing with the wildcard "*" and then use the name you find; this of course assumes that there'e only one file per day.
This would probably easiest with
filename oscmd pipe "ls filename&date.*.xls";
data _null_;
infile oscmd;
input;
* you may do some checks here to avoid problems if no file is found;
call symput('xls_filename',trim(_infile_));
run;
If you can't do that (NOXCMD), then this could be helpful: http://www.wuss.org/proceedings12/55.pdf
When I tried using a * as wildcard in the DATAFILE option for a delimited file it worked.
%let path=%sysfunc(pathname(work)) ;
proc export data=sashelp.class file="&path\class.txt" dbms=dlm replace ;
run;
proc import out=class datafile="&path\clas*.txt" dbms=dlm replace ;
run;
I am not able to understand you both said.
using filename and data _null_ how the import it is done. is it dataset after importing saved to any library.
If you know that there is only one file with that day of week and some unknown time of day in the filename then use a WILDCARD in the filename and SAS and the operating system will find the file without you needing to know the name.
proc import datafile="D:\emp\DATAExport &LAST_WEEK_MONDAY*.xls"
data=last_week_monday replace
...
If it is possible that there is more than one such file then this method might not work. You will need to test what it does if there are more than one.
PROC IMPORT OUT= data_1
DATAFILE="D:\emp\DATAExport &LAST_WEEK_MONDAY*.xls"
DBMS=EXCEL REPLACE;
GETNAMES=YES;
RUN;
ERROR: Connect: Failure creating file.
ERROR: Error in the LIBNAME statement.
Connection Failed. See log for details.
Well that's too bad. The LIBNAME statement is not as smart as the INFILE statement.
%LET TODAY1=%SYSFUNC(TODAY(),DATE9.);
%LET LAST_WEEK_MONDAY=%SYSFUNC(INTNX(WEEK.2,"&TODAY1."D,-1,B),YYMMDDD10.);
%put &=TODAY1 &=&LAST_WEEK_MONDAY;
data _null_;
length filename $256;
infile "D:\emp\DATAExport &LAST_WEEK_MONDAY*.xls" filename=filename obs=1;
input @;
call symputx('FILENAME',filename);
run;
proc import datafile="&filename" ....
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: