BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JNC
Fluorite | Level 6 JNC
Fluorite | Level 6

when I submit the following data step

data temp.testdata;

fname="abc";

run;

SAS automatically assigns a permanent libref by the name of temp pointing to "C:\Users\nnnn\AppData\Local\Temp". However this if I give any other libref that was not previously assigned with libname statement, it gives an error "libref not assigned"

Please help me to understand this

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Its a throw back to SAS's mainframe roots.  In JCL you used a DD card to map DDNAME to a physical file.   SAS would use the DDNAME as the LIBREF ref.

//MYLIB DD DSN=.......
//SYSIN DD *
data mylib.testdata; fname='abc'; run;
/*

So when they rolled out SAS for other operating systems they decided that if you had an environment variable defined with the name you are using as a LIBREF in your code (but you hadn't define a libref yet) then the value of that environment variable would be used as path for the library.

View solution in original post

4 REPLIES 4
AMSAS
SAS Super FREQ

I'm assuming this is on Windows and it is documented here:

https://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#usedatalibs.htm

 

It's an environment variable 
In the screen shot below, you can see the libref temp is assigned to c:\users\snzroo\appdata\local\temp and to the right you can see the command prompt window where I echoed the TEMP environment variable.

 

AMSAS_0-1605719544912.png

 

Tom
Super User Tom
Super User

Its a throw back to SAS's mainframe roots.  In JCL you used a DD card to map DDNAME to a physical file.   SAS would use the DDNAME as the LIBREF ref.

//MYLIB DD DSN=.......
//SYSIN DD *
data mylib.testdata; fname='abc'; run;
/*

So when they rolled out SAS for other operating systems they decided that if you had an environment variable defined with the name you are using as a LIBREF in your code (but you hadn't define a libref yet) then the value of that environment variable would be used as path for the library.

JNC
Fluorite | Level 6 JNC
Fluorite | Level 6

Thank you @Tom @AMSAS   for the quick reply. This helps to understand clearly

 

Regards,

JNC

MartinMincey
SAS Employee

To reinforce an answer from yesterday, SAS is able to use TEMP as a default/pre-defined LIBREF due to the fact that with most installs of Windows, TEMP is defined as a Windows environment variable.  One way to view all of the environment variables that are defined in Windows is to bring up your Windows control panel and then choose System, then Advanced System Settings, and then click the Advanced tab.  In this window, click the button titled "Environment Variables" and then take a look at the environment variables defined under "User Variables".  

 

For most users, TEMP points to the following Windows directory:

C:\Users\userid\AppData\Local\Temp

 

Even though this appears to be a temporary location, note that any files and data sets written to TEMP by SAS will not be deleted from disk upon SAS termination.  This is different than using the default SAS WORK location (where files and data sets written to work are deleted from disk upon normal SAS termination).    

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1442 views
  • 11 likes
  • 4 in conversation