%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?
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
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.
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!
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.
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:
If you want to use a path on your computer, sas needs to be running on the very same machine.
@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.
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.
and your paths don't look right as well.
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.
Ready to level-up your skills? Choose your own adventure.