Posts

Showing posts with the label Macros

SAS Macros that Convert a Directory of Transport Files

There is a set of SAS macros, converts a directory of transport files to a directory of SAS data sets and format catalogs (and vice versa). To see how to invoke the macros, look at the test following the last macro. The macros make the assumption that transport files created from data sets have the extension .xpt, and transport files created from format catalogs have the extension .xpf. %expfmts : This macro will convert an existing format catalog into a data set in transport format. % expdset : This macro will convert an existing SAS data set into a transport file. %impfmts : This macro will convert a transport CNTLOUT data set into a native format catalog. %impdset : This macro will convert a transport data set into a native SAS data set. %getnames : This macro will create a SAS data set consisting of a variable called FILENAME. There will be one observation for each file in the specified directory with the specified extension. Direct link: http://www.sas.co...

Renaming All Variables in a SAS Data Set Using the SASHELP VIEWS

*Create a temporary dataset... DSN; data dsn; a=1; b=2; c=3; d=4; e=5; f=6; run; % macro test(lib,dsn); */1)*/ data _null_; set sashelp.vtable(where=(libname=" &LIB " and memname= "&DSN" )); call symput( 'nvars', nvar); run; */2)*/ data dsn; set sashelp.vcolumn(where=(libname ="&LIB" and memname= "&DSN" )); call symput(cats( "var" ,_n_),name); run; */3)*/ proc datasets library =&LIB; modify &DSN; rename % do i = 1 % to &nvars; &&var&i=Rename_&&var&i. % end ; ; quit; run; % mend ; %test (WORK,DSN); After submitting the above program... the output looks like this.... Output: Rename_a Rename_b Rename_c Rename_d Rename_e Rename_f 1 2 3 4 5 6 Here is a way I know of.. to rename all the variables in the dataset; It can be done using the SASHELP views as follows: 1) The 1st step of the program determines the total number of variables inside the dataset with the help of SA...