BookmarkSubscribeRSS Feed
ncorbett
Calcite | Level 5

Hello all,

New to SAS here!

I have a folder in which I will be dropping Excel Files (.xls) files. This is the format in which they come to me. The files have a date name. They will like this 08262021.xls.


I am trying to add a variable called "Date_Ordered", and for each line of each file add the name of the file. 

 

I've searched the depths of the internet to try to find a code that will do this, but I don't see anyone out there posting it.

 

Here is the code I've got so far, which will import each file:

PROC IMPORT OUT= PROMO.CONNECTRAW DATAFILE=
"\\KTCHQF1\PARTHOME\PARTS SALES & MARKETING\PROMO TRACKER\CONNECT\2021\RAW DATA\*.xls"
DBMS=XLS REPLACE;
NAMEROW=4;
DATAROW=5;
SHEET="PARTS REPORT";
getnames=no;

(what i want to add is:

Variable name is Order_Date and for each line of each file, give me the File name)
RUN;

 

Does anyone know what I can do to add a variable that will give me the file name for each line that I'm importing?

 

I've attached sample data, so when I import this file, I want under Order_Date, the data for each line from this file to say 08252021.

 

Please let me know if more info or clarification is needed. OR if there is already something out there that can help me. And thank you for your help!

2 REPLIES 2
PhilC
Rhodochrosite | Level 12

I think you should think about performing multiple PROC IMPORTS, one for each Excel file.  Our user @Tom has an excellent solution that you can template.  First he shows us away to read the filenames in the folder.  See the first part of the code here.

Solved: Re: macro to read all files together - SAS Support Communities 

 

Then using the same technique as Tom, adapt your PROC IMPORT code into Tom's second part, as well as the code to add the columns.

 

There are many ways to skin this cat, mind you.  I tend to use DOSUBL or CALL EXECUTE in the second part, Tomato-Tomaato.  This is another level of programming, writing programs to write programs.  Good luck.

ncorbett
Calcite | Level 5

Hi PhilC,

 

Thanks I will let you know how it works!

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 637 views
  • 0 likes
  • 2 in conversation