BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
yelkenli
Calcite | Level 5

This is a beginner question, as I have been working with SAS only on and off.

 

I work mostly in the 'work' folder and send to sasuser as needed. 

I searched around the help forums after the below bombed and did not find anything. 

 

Is there a way to send to a subfolder? 

 

data sasuser.subfolder.have;
set work.have;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just make the directory before hand and then define a different libref that points to the new directory.

 

Let's assume your SASUSER libref is configured to point to the directory ~/sasuser.v94 (typical on Unix installs of Foundation SAS).  So first create a new directory, let's call it ~/sasuser.v94/subdir.  Then in your SAS program define a libref that points to it.  Let's use the libref SUBDIR.

libname subdir "~/sasuser.v94/subdir";

Now you can reference SAS datasets in that directory by using a normal two level name with SUBDIR as the libref and the dataset name as the member name.

data subdir.have;
  set have;
run;

Personally I never write anything into SASUSER libref because when you have more than one SAS job running (and who doesn't if they are really using SAS for production work?) then you cannot get write access to it in all of them.   So instead just point your libref to some other more meaningful directory.

Examples:

libname proj1 '~/project1';
libname proj2 '~/project2';

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Just make the directory before hand and then define a different libref that points to the new directory.

 

Let's assume your SASUSER libref is configured to point to the directory ~/sasuser.v94 (typical on Unix installs of Foundation SAS).  So first create a new directory, let's call it ~/sasuser.v94/subdir.  Then in your SAS program define a libref that points to it.  Let's use the libref SUBDIR.

libname subdir "~/sasuser.v94/subdir";

Now you can reference SAS datasets in that directory by using a normal two level name with SUBDIR as the libref and the dataset name as the member name.

data subdir.have;
  set have;
run;

Personally I never write anything into SASUSER libref because when you have more than one SAS job running (and who doesn't if they are really using SAS for production work?) then you cannot get write access to it in all of them.   So instead just point your libref to some other more meaningful directory.

Examples:

libname proj1 '~/project1';
libname proj2 '~/project2';

 

SASJedi
SAS Super FREQ

The elements of a fully-qualified table reference in SAS don't correlate to physical folders in the file system. So, if you have write access to the SASUSER library, it's possible to create a subfolder there, you'd need to assign a different libref instead of using three-level notation. If that's what you want, then you could go about it like this (examples were tested using PC SAS):
1. Identify the physical location of the SASUSER library. The PATHNAME function can do that for you:

%put NOTE: The SASUSER library is located in %qsysfunc(pathname(sasuser));

In the log:

NOTE: The SASUSER library is located in C:\Users\myUserID\Documents\My SAS Files\9.4

&nbsp

You can use the DLCREATEDIR option to make SAS create a folder in the file system when assigning a libref, if the folder does not exist:
 

options dlcreatedir;
LIBNAME SUB "%qsysfunc(pathname(sasuser))\mySubFolder";
options nodlcreatedir;

From the log:
NOTE: Library SUB was created.
NOTE: Libref SUB was successfully assigned as follows:
Engine: V9
Physical Name: C:\Users\myUserID\Documents\My SAS Files\9.4\mySubFolder

Now, data sets written to the SUB library will be stored in the new mySubFolder folder.

data sub.have;
	set work.have;
run;

 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 193 views
  • 2 likes
  • 3 in conversation