Desktop productivity for business analysts and programmers

How to copy the all datasets structure from one library to another new library through sas base code

Reply
Contributor SKG
Contributor
Posts: 55

How to copy the all datasets structure from one library to another new library through sas base code

How to copy the all datasets structure from one library to another new library through sas base code

Super User
Super User
Posts: 7,970

Re: How to copy the all datasets structure from one library to another new library through sas base

In what sense?  You just want to copy everything from one library to another:

proc copy in=inlib out=outlib;
run;

If you want to create empty versions then a bit more code, and it doesn't really make sense doing this at all:

data _null_;
  set sashelp.vcolumn (where=(libname="INLIB"));
  by memname;
  if first.memname then do;
    call execute('proc sql; create table OUTLIB.'||strip(memname))||' (');
    call execute(strip(name)||ifc(type="char","CHAR("||strip(put(length,best.))||")","NUM"));
  end;
  else call execute(","||strip(name)||ifc(type="char","CHAR("||strip(put(length,best.))||")","NUM"));
  if last.memname then call execute(');quit;');
run;

This will generate the code necessary to create each table.  Again, this is Not advised.

You could also sql describe table to a text file and then include that.

Contributor SKG
Contributor
Posts: 55

Re: How to copy the all datasets structure from one library to another new library through sas base

59 data _null_;
60 set sashelp.vcolumn (where=(libname="Maps"));
61 by memname;
62 if first.memname then do;
63 call execute('proc sql; create table work.'||strip(memname)||' (');
64 call
64 ! execute(strip(name)||ifc(type="char","CHAR("||strip(put(length,best.))||")","NUM"));
65 end;
66 else call
66 ! execute(","||strip(name)||ifc(type="char","CHAR("||strip(put(length,best.))||")","NUM"));
67 if last.memname then call execute(');quit;');
68 run;

NOTE: The map data sets in library MAPSGFK are based on the digital maps from GfK GeoMarketing
and are covered by their Copyright. For additional information, see
http://support.sas.com/mapsonline/gfklicense.
NOTE: There were 0 observations read from the data set SASHELP.VCOLUMN.
WHERE libname='Maps';
NOTE: DATA statement used (Total process time):
real time 12.31 seconds
cpu time 1.10 seconds

 

 

I'm not getting any observations from this code.

Super User
Super User
Posts: 7,970

Re: How to copy the all datasets structure from one library to another new library through sas base

And did you look at the view vcolumn in the library sashelp?  If you did you will see that libname variable is all upper case:

set sashelp.vcolumn (where=(libname="MAPS"));

 

 

Super User
Posts: 10,035

Re: How to copy the all datasets structure from one library to another new library through sas base

Make a macro to go through one of the both following code.

 

1)  

data x.have;

 set y.have;

 stop;

run;

 

2)

proc sql;

create table x.have like y.have;

quit;

Super User
Posts: 10,035

Re: How to copy the all datasets structure from one library to another new library through sas base

libname x v9 'c:\temp';

data _null_;
 set sashelp.vmember(keep=libname memname where=(libname='X'));
 call execute(catt('data work.',memname,';set x.',memname,';stop;run;'));
run;
Super User
Super User
Posts: 7,970

Re: How to copy the all datasets structure from one library to another new library through sas base

Yes, good point @Ksharp, avoids need to do each column processing.  

Contributor SKG
Contributor
Posts: 55

Re: How to copy the all datasets structure from one library to another new library through sas base

69 data _null_;
70 set sashelp.vmember(keep=libname memname where=(libname='Maps'));
71 call execute(catt('data work.',memname,';set x.',memname,';stop;run;'));
72 run;

NOTE: There were 0 observations read from the data set SASHELP.VMEMBER.
WHERE libname='Maps';
NOTE: DATA statement used (Total process time):
real time 0.12 seconds
cpu time 0.12 seconds

 

 

I'm not getting any observations from this code.

Super User
Posts: 10,035

Re: How to copy the all datasets structure from one library to another new library through sas base

[ Edited ]

Library name should be upcase.

 

libname='MAPS'

 

also change

;set x.',memname

into

;set maps.',memname

Super User
Posts: 5,431

Re: How to copy the all datasets structure from one library to another new library through sas base

To copy the full structure, create a macro that copies the tables usin PROC APPEND with obs=0 dataset option on the DATA= data set.
This way you will also be able to replicate structural components such as indexes and constraints.
Data never sleeps
Super User
Super User
Posts: 7,060

Re: How to copy the all datasets structure from one library to another new library through sas base

Use PROC COPY to copy the datasets. Use option OBS=0 to prevent it from copying the data.

options obs=0;
proc copy inlib=IN outlib=OUT;
run;
options obs=max;
Ask a Question
Discussion stats
  • 10 replies
  • 676 views
  • 6 likes
  • 5 in conversation