I tried to assingn a libref name so that i don't have to us the full pathname every time. The name is assinged but when i try to use it is does not work.
This is the code i used.
libname GD "H:\Mijn Documenten\Finacien\mi\Mi 2021\Glims";
run;
proc import
datafile = "GD\Factuur_210201_01.xls" out=glims_data_2021;
range="blad1$B12:0";
run;
This is the log I get
NOTE: Libref GD was successfully assigned as follows:
Engine: V9
Physical Name: H:\Mijn Documenten\Finacien\mi\Mi 2021\Glims
30 run;
31 *importeren van de data;
32 proc import
33 datafile = "GD\Factuur_210201_01.xls" out=glims_data_2021;
34 range="blad1$B12:0";
35
36 run;
ERROR: Unable to open file C:\WINDOWS\system32\GD\Factuur_210201_01.xls. It does not exist or it is already opened exclusively by another user, or you need permission to view its data.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
Can someone tell me what i do wrong. Thanks in advance
For the use case you describe, I recommend using a macro variable like so:
%let dataPath = H:\Mijn Documenten\Finacien\mi\Mi 2021\Glims;
proc import
datafile = "&dataPath\Factuur_210201_01.xls" out=glims_data_2021;
range="blad1$B12:0";
run;
The %LET creates the macro variable. Macro variable just contain some text. With &varname you can place the text stored in the macro variable anywhere you need it in your code.
When importing Excel files using Proc IMPORT you will not use a libref, but rather a physical filename.
So change your code from
proc import
datafile = "GD\Factuur_210201_01.xls" out=glims_data_2021;
range="blad1$B12:0";
run;
to
proc import
datafile = "H:\Mijn Documenten\Finacien\mi\Mi 2021\Glims\Factuur_210201_01.xls" out=glims_data_2021;
range="blad1$B12:0";
run;
And you should be fine.
The result of Proc IMPORT is a SAS dataset named glims_data_2021 in the WORK library. Where do you want to have your SAS data set stored?
BTW there is no need to use a RUN; after the LIBNAME statement.
Hello Bruno,
Thank you for your reply. This works but the reason I want to use a libname is that I need to import data from 3 years with 2 files per month so I would like to prevent typing the hole path every time. Is there a way to do this?
For the use case you describe, I recommend using a macro variable like so:
%let dataPath = H:\Mijn Documenten\Finacien\mi\Mi 2021\Glims;
proc import
datafile = "&dataPath\Factuur_210201_01.xls" out=glims_data_2021;
range="blad1$B12:0";
run;
The %LET creates the macro variable. Macro variable just contain some text. With &varname you can place the text stored in the macro variable anywhere you need it in your code.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.