BookmarkSubscribeRSS Feed
MariaD
Barite | Level 11

Hi All,

 

When you define libname concatenation and you create a new table, this is saved in the first path (if the path has available space). Is possible to configure that use the path with more free space?

 

Example:

 

Libname test ('/path1' '/path2');

 

data test.new;

  set seashelp.class;

run;

 

The table "new" is created by default in "/path1", the first path used in libname statement.

 

Regards,

7 REPLIES 7
Haikuo
Onyx | Level 15

No, I can't think of any built-in features in SAS that support this function. And there is a possibility that you won't be able to do at all depending on your SAS deployment (eg. Admin may not let you call for OS command). . You will need to pre-check the available storage space for each ‘path’ by calling OS commands, again, depending on the OS, the commands are different, pipe and parse the useful information back to SAS, do the comparison, then realign the order in your final Libname statements. As you can see, it could get to certain level of complexity and Macro language will likely to be required.  

GinaRepole
SAS Employee

I don't believe what you're asking for is possible, using libname concatenation

 

What you might be able to do instead is create multiple libraries, one concatenating all your relevant inputs together and the rest referring to each component of the concatenation. From there, I found this pre-written macro program that you might be able to customize to calculate free space for each particular folder.

MariaD
Barite | Level 11

Thanks @GinaRepole.

 

The problem is I need to use two filesystem as one. For some operation system limitation, it's not possible to have a big filesystem, so I have two but I needed working as one.

 

I understand that, in library concatenation, when a SAS file is opened for output, it is created in the first path that is listed in the concatenation. Even if there is a file with the same name in another part of the concatenation. This is a huge problem for me. 

 

For example:

 

libname test ('/path1' '/path2');

 

data test.class;

  set seashelp.class;

run;

 

In this case, even if CLASS already exists in '/path2', instead to recreate the table, a new version of the table is created in '/path1'. There is workaround for this behaviour? Any suggestion?

 

Regards,

Haikuo
Onyx | Level 15

Ok, I see what you are facing. Hopefully the following code can mitigate some of your pain. You can, however, realize the same functionality by using Macro, but I find it is easier to write/debug code in the combination of data step and call execute().


%let tname=CLASS; /*the table name you choose to create downstream*/

/*put your multiple path in a data set, you will find it is so much easier to manuver later on*/
data path;
	infile cards truncover;
	input path $100.;
	cards;
'/path1/'
'/path2/'
;


data _null_;
	set path end=last;
	length cat $ 200;
	retain cat;
	cat=catx(' ',path); /*for _big library assignment*/
	/*create dynamic libraries for each path*/
	call execute (
		'libname '
		||"_"
		||left(put(_n_,best.))
		||" "
		||path
		||";"
		)
	;

	if last then
		do;
		/*identify the libraries that have the table with the same name*/
			call execute ( 
				'proc sql;
				create table tmp as
				select libname  from dictionary.tables where memname='
				||'"'
                ||STRIP("&TNAME.")
                ||'"'
                ||'; QUIT;'
				);
				/*delete those tables if they exist*/
			CALL EXECUTE ('
				data _null_;
				set tmp nobs=nobs;
				if nobs>0 then
				call execute (
				"proc datasets library="
				||libname
				||";"
				||"delete &TNAME.;" 
				|| "run;"
				);
				
				run;
				');
				/*assign the concatenated library*/
			call execute (
				'libname _big ('
				||cat
				||');'
				);
		END;
run;



ChrisNZ
Tourmaline | Level 20

>There is workaround for this behaviour? Any suggestion?

I'd suggest deleting the table before creating a new one.

 

One deletion call (proc delete or proc datasets or proc sql+drop) will only delete one instance.

 

So you need as many deletions as there are copies of a table in each of the paths, if that makes sense.

 

This macro will do this. 

Here, it performs two deletions;

libname A 'c:\temp';
libname B (A WORK);
                
data A.T 
     WORK.T; 
run;

%macro fulldelete(table);
  %do %while( %sysfunc(exist(&table)) );
    proc delete data=&table.; run;
  %end;
%mend;

%fulldelete(B.T); 




 

 

 

 

 

SuryaKiran
Meteorite | Level 14

 

LIBNAME LIB1 "/path1";

LIBNAME LIB2 "/path2";

 

LIBNAME LIB (LIB1 LIB2);

 

data LIB.OUTPUT;

In this case the output will by default go into LIB1. If you want to sent the output to more free space then use SASHELP.VTABLE and calculate the filesize in each LIB1 and LIB2 and write a logic to send to more free space library.

Thanks,
Suryakiran
MariaD
Barite | Level 11

Thanks for all the suggestions!

 

Regards,

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1929 views
  • 4 likes
  • 5 in conversation