DATA Step, Macro, Functions and more

How to copy views and indexes

Accepted Solution Solved
Reply
Super Contributor
Posts: 400
Accepted Solution

How to copy views and indexes

Hello,

 

I'm making back up copies of directories on a SAS Share sever from a production SAS Share server.  I am able to create a macro to get a list of "DATA" tables and then create a copy of them in a new location.  My issue is that some of the locations I'm copying from have views (*.sas7bvew) and index (*.sas7bndx) files and I'm not sure how to make a copy in the new location.  In my code I'm looping through a list of libnames and taking the data tables and making a work copy then copying the table to my backup location.

 

data lib_list ;
	length lib $10 ;
	input lib $ ;	
cards;
Lib1
Lib2
Lib3
Lib4
;
run;

data _null_ ;
	set lib_list end = last ;
	call symput('libname'||trim(left((_n_))), trim(left(lib)) ) ;	
	call symput('nlibs', trim(left(_n_))) ;
run ;

%macro Get ;	
	%do i = 1 %to &nlibs. ;
		%let x=Share1 ;
		options comamid=tcp ;

		libname &&libname&i.  server=x.Shr1 access=readonly ;
		
		proc sql ;
		create table tabs
		as
		select *
		from dictionary.tables
		where libname = "&&libname&i."
		and memtype = 'DATA'
		;
		quit ;
		
		data _null_ ;
			set tabs end = last ;
			call symput('tabname'||trim(left((_n_))), trim(left(memname)) ) ;	
			call symput('ntabs', trim(left(_n_))) ;
		run ;
		
		%do j = 1 %to &ntabs. ;
			data &&tabname&j. ;
				set &&libname&i...&&tabname&j. ;
			run ;	
		%end ;
				
		%let w=Share2 ;
		options comamid=tcp ;
		libname &&libname&i.  server=w.Shr2 ;
				
		%do y = 1 %to &ntabs. ;
			data &&libname&i...&&tabname&y. ;
				set &&tabname&y. ;
			run ;	
		%end ;

		proc datasets lib=work nolist memtype=data ;
			save lib_list  ;
		quit ;
	%end ;
%mend Get ;

options mprint ;
%Get ;	

Any help would be greatly appreciated.

 

 

 


Accepted Solutions
Solution
‎09-09-2016 11:59 AM
Occasional Contributor
Posts: 6

Re: How to copy views and indexes

Posted in reply to jerry898969

PROC COPY is not an option for you ?

View solution in original post


All Replies
Solution
‎09-09-2016 11:59 AM
Occasional Contributor
Posts: 6

Re: How to copy views and indexes

Posted in reply to jerry898969

PROC COPY is not an option for you ?

Super Contributor
Posts: 400

Re: How to copy views and indexes

[ Edited ]

Hi Michiel,

 

Will proc copy bring over the views?  I didn't think it did, but I could be wrong.

 

thanks

Super Contributor
Posts: 400

Re: How to copy views and indexes

I ran it again on a specific directory and it looks like it brought everything over. 

 

Server 1 to Work
proc copy in=temp out=WORK constraint=yes index=yes ;			
run;

Work to Server 2
proc copy in=work out=temp2 constraint=yes index=yes ;			
run;

Thank you

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 424 views
  • 0 likes
  • 2 in conversation