I wrote the below code but got an error like 'library Apple does not exist'. It seems that the macro variable was not recognized.... could you please help me to fix the error?
%MACRO CREATE(months);
LIBNAME APPLE&months "C:\FRUITS\APPLE&&months";
DATA season&months;
SET APPLE&months..good;
RUN;
%MEND CREATE;
%CREATE;
You only need one ampersand when addressing macro variables.
thanks! it does not still work..can you help me what I should try?
%MACRO CREATE(months);
LIBNAME APPLE&months "C:\FRUITS\APPLE&months";
DATA season&months;
SET APPLE&months..good;
RUN;
%MEND CREATE;
%CREATE;
The way you have written that macro the value passed for MONTHS can have at the most only three characters. Otherwise the libref being defined will be longer than 8 characters.
But since you did not pass any value for MONTHS that is not the cause of the error.
The extra & is probably not the issue. That will just cause SAS to convert &&MONTHS to &MONTHS so it just adds a little extra work.
Sounds like the directory you are trying to reference does not exist. Do you really have a directory named:
"C:\FRUITS\APPLE"
on the machine where your SAS code is running?
Turn on the MPRINT option to see what SAS code the macro is generating.
Normally you wouldn't add anything to the libref. The libref is already a place holder that pointer to the real directory. So if you have a series of directories named : APPLEJAN, APPLEFEB, APPLEMAR you could always use the libref APPLE to point to the specific one you want to use now rather than making multiple different librefs.
oh...i see... i sincerely appreciate your help!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.