DATA Step, Macro, Functions and more

Import filename from the local directory

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Import filename from the local directory

i want to call the fill name from the local directory. my file name will be month.xlsx. month name will be to the current month filename.

How can i include in the proc import the dynamic filename.


Accepted Solutions
Solution
‎03-20-2018 11:54 AM
Super User
Posts: 23,754

Re: Import filename from the local directory


@radha009 wrote:

i want to call the fill name from the local directory. my file name will be month.xlsx. month name will be to the current month filename.

How can i include in the proc import the dynamic filename.


So if you ran it now would you expect to find February.xlsx or March.xlsx

The easiest way seems to use a macro variable.

 

%let month = %sysfunc(today(), monname20.);
%put &month.;

View solution in original post


All Replies
Valued Guide
Posts: 580

Re: Import filename from the local directory

If sas is not running locally, you can't access local files.

Contributor
Posts: 70

Re: Import filename from the local directory

Posted in reply to andreas_lds

my sas is running locally. i have full path in the Proc import data file. i have to change every month my script to the change the file name to generate a reprot.i am looking something that look for the filename from the folder.

Valued Guide
Posts: 580

Re: Import filename from the local directory

Are you using display manager or enterprise guide? With EG you could add a prompt allowing you to select the file to import. The name can be computed if rules exist. If you just want the latest file in a folder, using cmd/powershell to get the filename is recommended, because, compared to a full-implementation in sas, less code is required. If you want / have to do it in sas have a look at the functions dopen, dnum, dread, fopen, finfo ...

Solution
‎03-20-2018 11:54 AM
Super User
Posts: 23,754

Re: Import filename from the local directory


@radha009 wrote:

i want to call the fill name from the local directory. my file name will be month.xlsx. month name will be to the current month filename.

How can i include in the proc import the dynamic filename.


So if you ran it now would you expect to find February.xlsx or March.xlsx

The easiest way seems to use a macro variable.

 

%let month = %sysfunc(today(), monname20.);
%put &month.;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 105 views
  • 0 likes
  • 3 in conversation