BookmarkSubscribeRSS Feed
KC_16
Fluorite | Level 6

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

2 REPLIES 2
unison
Lapis Lazuli | Level 10

https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n0js70lrkxo6uvn1fl4a5aafnlgt.htm&docse...

 

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).

-unison
Kurt_Bremser
Super User

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).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 764 views
  • 2 likes
  • 3 in conversation