DATA Step, Macro, Functions and more

Prompt window to select file path to import (SAS BASE)

Accepted Solution Solved
Reply
Regular Contributor
Posts: 182
Accepted Solution

Prompt window to select file path to import (SAS BASE)

Hi everyone,

Could anyone please help me with a code that will allow the user to brow to the location of an excel file to import to SAS?

I am using SAS 9.4 Base (not EG)

Thank you 

Kind regards

AM


Accepted Solutions
Solution
a month ago
Super User
Posts: 23,735

Re: Prompt window to select file path to import (SAS BASE)

If you're going to need prompts I would suggest switching to SAS EG or Studio or AddIn for Microsoft Office. 

 

Otherwise you're stuck rolling your own via JavaScript or another application interface. SAS Base is not designed for interactive solutions like this. 

 

Usually, if it's base I have parameters at the top and people have to copy/paste in the path.  To import all sheets, you can use the XLSX libname approach and PROC COPY. This should copy all the sheets with data to the WORK library.

 

%let pathFileImport = C:\_localdata\temp\Demo.xlsx;


libname demo xlsx "&pathFileImport";

proc copy in=demo out=work;
run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 9,368

Re: Prompt window to select file path to import (SAS BASE)

Hi:

  If you are already using Base SAS 9.4, the Windowing Environment has an Import Data menu option that allows you to browse to the location of a file to import: File --> Import Data --> and then follow the prompts in the Import Window:

dms_import_data.png

  Hope this helps,

 

Cynthia

Regular Contributor
Posts: 182

Re: Prompt window to select file path to import (SAS BASE)

Posted in reply to Cynthia_sas

Thanks Cynthia

I am aware of the import functionality through the drop-down menu, I was however looking for achieving something similar using the code itself.

I have looked into %window but not sure I can get a pop up menu with a browse button to allow the user to choose the path of the excel file.

The issue is that the excel file will contain multiple sheets, so i was trying to capture the file path through a prompt to the user, then use proc import to import all the sheets from the excel file

Thanks again

AM

SAS Super FREQ
Posts: 9,368

Re: Prompt window to select file path to import (SAS BASE)

Hi:

  I do not believe that %WINDOW will allow you to implement a browse button, because the browse button would have to go out to the operating system and then return the results to the %WINDOW program. This is probably a question for Tech Support. I don't actually recommend using %WINDOW because it has limited usefulness in a client/server scenario. You might try investigating SAS Studio, you can build your own tasks and, in fact, there is an Import Task that you might even be able to start with as a model. It was my understanding that SAS Studio was available with Base 9.4 -- when I installed the latest version of SAS 9.4, I got all 3 interfaces: SAS on Windows, SAS EG and SAS Studio. Here's what the Import Task looks like in SAS Studio:

studio_import_task.png

 

Cynthia

Solution
a month ago
Super User
Posts: 23,735

Re: Prompt window to select file path to import (SAS BASE)

If you're going to need prompts I would suggest switching to SAS EG or Studio or AddIn for Microsoft Office. 

 

Otherwise you're stuck rolling your own via JavaScript or another application interface. SAS Base is not designed for interactive solutions like this. 

 

Usually, if it's base I have parameters at the top and people have to copy/paste in the path.  To import all sheets, you can use the XLSX libname approach and PROC COPY. This should copy all the sheets with data to the WORK library.

 

%let pathFileImport = C:\_localdata\temp\Demo.xlsx;


libname demo xlsx "&pathFileImport";

proc copy in=demo out=work;
run;
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 122 views
  • 5 likes
  • 3 in conversation