![]() | ![]() | ![]() | ![]() | ![]() |
Note: This sample can be used to rename a group of variables when a numbered range variable list is not feasible. Below is an example of a numbered range variable list using RENAME.
RENAME COL1-COL5=NEW1-NEW5;
For more information about SQL Dictionary Tables, please refer to SAS Language Reference: Concepts.
/* Create a sample data set. Note the naming pattern of COL1-COL5 is */
/* incomplete. Since COL4 is missing, a numbered range list can not */
/* used for this rename. */
data a;
col1=1;
col2=2;
col3=3;
col5=5;
x=123;
run;
/* Use SQL to create the macro variable VARLIST by retrieving the */
/* variable names from DICTIONARY.COLUMNS. Verify the LIBNAME and */
/* MEMNAME values match your existing data set. Note the values */
/* must be specified in upper case. 'NEW' will replace 'COL' for */
/* the appropriate variables. */
proc sql noprint;
select trim(name)||'=NEW'||substr(name,4)
into :varlist separated by ' '
from DICTIONARY.COLUMNS
WHERE LIBNAME EQ "WORK" and MEMNAME EQ "A"
and upcase(name) like 'COL%';
quit;
/* Use PROC DATASETS to do the rename. Again, verify the libref and */
/* member name match your data set. */
proc datasets library=work nolist;
modify a;
rename &varlist;
quit;
/* Confirm changes with a PROC CONTENTS */
proc contents data=a;
run;/* partial output from PROC CONTENTS */ Alphabetic List of Variables and Attributes # Variable Type Len 5 X Num 8 1 NEW1 Num 8 2 NEW2 Num 8 3 NEW3 Num 8 4 NEW5 Num 8
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> SQL SAS Reference ==> DATA Step |
| Date Modified: | 2006-01-26 03:03:11 |
| Date Created: | 2006-01-17 16:33:14 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | All | n/a | n/a |





