How to copy the all datasets structure from one library to another new library through sas base code
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.
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.
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"));
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;
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;
Yes, good point @Ksharp, avoids need to do each column processing.
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.
Library name should be upcase.
libname='MAPS'
also change
;set x.',memname
into
;set maps.',memname
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.