Hi,
I need to create a proc import and import a csv from a previous run. I have an excel file of which is date stamped
Examples:
All_Order_0219
All_Order_0619
All_Order_0719
All_Order_0919
As you can see, there isn't a file for each month as the code is run on an ad-hoc basis and currently, I manually update my PROC IMPORT to reference the most recent file.
What I am trying to do is avoid the user from having to manually state which file to import (below) and ideally, I'd like my code to look at the most recent file and automatically import, is there anyway of doing this please?
Proc Import
Datafile='E:\Processing\Orders\All_Order_0919.xls'
Out=Work.All_Order_Previous_Run
DBMS=XLS
replace;
run;
Thanks
I'd use something like this macro to get all of the filenames in your directory with the xls extension. From there you would need to determine how to extract the most recent file (based on your naming convention) and then take that result and throw it into a macro variable.
Start by taking the macro in that link and running something like this:
%list_files(E:\Processing\Orders,xls)
And let's see the output (assuming it's safe to share).
Step #1: reverse the order of the date in your filenames (YYMM instead of MMYY). That simplifies the solution by at least 50%.
Maxim 33: Intelligent Data Makes for Intelligent Programs (is also true for filenames).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.