BookmarkSubscribeRSS Feed
leeleelee
Calcite | Level 5
%macro file_yr (year=year);

libname e "C:Location\Folder";

%let e_file = C:Location of data\Folder of data;

data e.nameoffile;

infile "e_file\nameoffile.txt" 

%mend;

proc sql;
select count(*) as N from e.nameoffile;
Quit;

log:
ERROR: File e.nameoffile.DATA does not exist.

 Hello, how do I make sure this runs?

10 REPLIES 10
tarheel13
Rhodochrosite | Level 12
You are missing a semicolon after your file path on infile statement
leeleelee
Calcite | Level 5

The lack of a semicolon does not matter in my case, I'll provide more code/context:

%macro file_yr (year=year);
libname e "C:\Location\Folder";
%let e_file = C:\Location of data\Folder of data;

data e.nameoffile;

infile "&e_file.\nameoffile.txt" 
firstobs = 2 dlm = "|" lrecl=32767 missover truncover dsd;
/* inserted input and format for headers here*/
%mend;

proc sql;
select count(*) as N from e.nameoffile;
Quit;

/* record count check*/
proc sql;
create table e_cnts as
select
count (*) as Num_Records
from nameoffile
;
quit;

proc export
data=e_cnts
dbms=xlsx
outfile="C:\location_of_output"
replace;
run;

log:
ERROR: libref e is not assigned
ERROR: File WORK.nameoffile.DATA does not exist.
ERROR: File Work.e_cnts.DATA does not exist
tarheel13
Rhodochrosite | Level 12

Have you tried running any of this code outside of a macro first? Did you get the folder path right? I'm just trying to think of reasons why the library isn't getting assigned. 

leeleelee
Calcite | Level 5

Hi, the folder path is right, and I'm new to sas so not sure what running the code outside of the macro means.

 

Thank you!

tarheel13
Rhodochrosite | Level 12

Normally, when people begin writing a macro, they first get the code working outside a macro before macrotizing it. I mean to try running the libname statement by itself and not between %macro and %mend.

andreas_lds
Jade | Level 19

The terms "new to sas" while having %macro-statement in the code is something that does not fit. Start learning SAS by not using macro-variables and macros at all.

 

The message "libref not assigned" has always one of two reasons:

  1. The path does not exist.
  2. The path exists, but is not accessible by your sas-process.

If you want to use a path on your computer, sas needs to be running on the very same machine.

Kurt_Bremser
Super User

@leeleelee wrote:

... and I'm new to sas ...


Then you positively should NOT try your hand at macro coding now. Spend lots of time first getting acquainted with the basic elements of SAS coding (data step and the most often applied procedures, including REPORT and SQL) before you try to make code dynamic through macros.

 

Personal experience: I had three weeks of programming courses in Heidelberg before I attended the macro course.

Kurt_Bremser
Super User

You define a macro, but you never call it.

And you define a macro parameter (year) which you never use in the macro.

Remove the %MACRO and %MEND statements, and rerun your code. (this means "outside of a macro")

Then copy/paste the whole log into a </> window.

Patrick
Opal | Level 21

and your paths don't look right as well.

Patrick_0-1632388684840.png

 

Astounding
PROC Star
To refer to the macro variable in the INFILE statement, refer to &efile, not efile.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2172 views
  • 1 like
  • 6 in conversation