BookmarkSubscribeRSS Feed
LeeJenson
Calcite | Level 5
Hi,

I am at a loss as to why my macro variable DATA_FOLDER does not work
with my proc import. I have tried various combinations using a " and a
' defining the variable and in the proc import but any combination I
seem to use does not work. Here I am using single quotes defining the
macro variable and no quotes around the usage of the variable.

6721 %macro test;
6722 %let data_folder = 'c:\';
6723 libname test &data_folder.;
6724 proc import
6725 datafile = &data_folder.'test.xls'
6726 out = test.test1 dbms=excel replace;
6727 run;
6728 %mend test;
6729 %test;
MPRINT(TEST): libname test 'c:\';
NOTE: Libname TEST refers to the same physical library as ACR.
NOTE: Libref TEST was successfully assigned as follows:
Engine: V9
Physical Name: c:\
MPRINT(TEST): proc import datafile = 'c:\''test.xls' out =
test.test1 dbms=excel replace;
MPRINT(TEST): AEXC;
MPRINT(TEST): run;
ERROR: Unable to import, file c:\'test.xls does not exist.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
9 REPLIES 9
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
As revealed in your log, you have stray tick/quotation marks coded. You should not need to use them in your code.

Scott Barry
SBBWorks, Inc.
LeeJenson
Calcite | Level 5
Scott,

I did remove the quotes but them it had a problem with my drive letter!

Lee
Paige
Quartz | Level 8
While you didn't say what operating system you use, I will assume that it is some version of Windows, in which case you wouldn't put c:\ in any quotes whatsoever in macro variable data_folder.

After you fix that, in the PROC IMPORT statement, you again have quotes in the wrong places. It should look like:

proc import datafile="&data_folder\test.xls" ...

You don't want quotes anywhere in the interior of the datefile=" ", you just want quotes at the beginning and end of whatever text string represents your file.
LeeJenson
Calcite | Level 5
Paige,

When I removed quotes it had a problem with e:\ so I am not sure how I pass the drive location to my code?

yes sorry its windows...

Lee
Paige
Quartz | Level 8
Lee, please show us your code and the SASLOG, and we will be able to help.

Saying "it had a problem" doesn't allow us to provide any help at all.
Cynthia_sas
SAS Super FREQ
Hi:
As Paige suggests, seeing your LOG would be most helpful. One suggestion...are you sure that your E drive is available??? For example, review this SAS log:
[pre]
192 %let data_folder = e:\;
193 libname test "&data_folder.";
NOTE: Libref TEST was successfully assigned as follows:
Engine: V9
Physical Name: e:\

194 %let data_folder = j:\;
195 libname test "&data_folder.";
NOTE: Library TEST does not exist.

[/pre]

On my windows system, I DO have an E: drive, but I do NOT have a J: drive.

As a general rule of thumb, it is a bad idea to "pre-quote" your macro variables in the %LET statement. Macro variables are just character strings and quotes belong in the statements where you USE the macro variables.

For example in these two %LET statements below the second (unquoted) value for 16 is the correct usage:
[pre]
%let age = '16';
%let age = 16;
[/pre]

As you can see from this LOG, with quotes inside &AGE, my WHERE statement is incorrect:
[pre]
196 %let age = '16';
197 proc print data=sashelp.class;
198 title "1) Wrong: Students who are &age";
199 where age = &age;
ERROR: WHERE clause operator requires compatible variables.
200 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

201
202 %let age = 16;


203 proc print data=sashelp.class;
204 title "2) Right: Students who are &age";
205 where age = &age;
206 run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
WHERE age=16;
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.18 seconds
cpu time 0.03 seconds

[/pre]

This paper is a good introduction to Macro processing concepts.
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
LeeJenson
Calcite | Level 5
Thanks everyone for your input. It is working now. I will include a little log next time I refer to an error (sorry). I am still not 100% what I did wrong as I got myself really confused but its a mixture of putting quotes everywhere, rushing to meet deadlines and going through a big learning curve.

Thank you for your support and I will take time out to read the recommended reading.

:-)

Lee
SASPhile
Quartz | Level 8
Try this:
%macro test;
%let data_folder = c:\;
libname test "&data_folder.";
proc import
datafile = "&data_folder.test.xls"
out = test.test1 dbms=excel replace;
run;
%mend test;
%test;
Paige
Quartz | Level 8
Or the slightly more intuitive version

%macro test;
%let data_folder = c:\;
libname test "&data_folder"; /* No period here */
/* Two periods in next line, following a macro variable */
/* resolves to a single period. */
proc import datafile = "&data_folder..test.xls"
out = test.test1 dbms=excel replace;
run;
%mend test;
%test;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 9 replies
  • 4236 views
  • 0 likes
  • 5 in conversation