The following code creates an SAS program which contains the definitions of all the datasets in an library.
Useful when you want to duplicate an enviroment.
%MACRO descTable(inLibrary, outLibrary, file) ;
PROC SQL ;
CREATE TABLE work.table AS
SELECT memname AS table_name LENGTH=45
,name AS varName LENGTH=32
,type AS varType
,length AS varLength
,format AS varFormat
,npos AS varPos
FROM sashelp.vcolumn
WHERE libname = COMPRESS(UPCASE("&InLibrary."))
ORDER BY memname, npos ;
QUIT ;
FILENAME t "&file." ;
DATA _NULL_ ;
LENGTH codeText1 $250.
codeText2 $250.
codeText3 $250.
/*codeText4 $250.*/ ;
FILE t ;
SET work.table end=x ;
BY table_name ;
IF FIRST.table_name THEN DO ;
header = "DATA &OutLibrary.."||COMPRESS(table_name)||' ; ' ;
PUT header ;
END ;
/* Length bepalen */
IF UPCASE(COMPRESS(varType)) = "NUM" THEN
len = COMPRESS(PUT(varLength, 8.)) ;
ELSE
len = '
||COMPRESS(PUT(varLength, 8.)) ;
/* Totale text zetten */
/* Variable naam */
codeText1 = 'ATTRIB '||COMPRESS(varName) ;
/* Lengte */
codeText2 = 'LENGTH='||COMPRESS(len)||' ' ;
/* Format */
IF COMPRESS(varFormat) NE '' THEN
codeText3 = 'FORMAT='||COMPRESS(varFormat)||' ;' ;
ELSE
codeText3 = ' ;' ;
PUT @3 codeText1
@43 codeText2
@55 codeText3 ;
IF LAST.table_name THEN DO ;
PUT 'DELETE ;' ;
PUT 'RUN ;' ;
END ;
RUN ;
FILENAME t CLEAR ;
%MEND descTable ;
No comments:
Post a Comment