BookmarkSubscribeRSS Feed
ekim46
Fluorite | Level 6

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;

6 REPLIES 6
ekim46
Fluorite | Level 6

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;

Tom
Super User Tom
Super User

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.

ekim46
Fluorite | Level 6
yes i have the folder.Thanks!
Tom
Super User Tom
Super User

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.

ekim46
Fluorite | Level 6

oh...i see...  i sincerely appreciate your help!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 6 replies
  • 1271 views
  • 3 likes
  • 3 in conversation