|
> From: Nick .
> I have a SAS (V8.2) data set with, say, 5 fields (in my data
> set it has like 500 fields) called VAR1, VAR2,..., VAR5.
> I have an Excel data set that looks like this:
> A B
> VAR1 Age
> VAR2 Income
> VAR3 Gender
> VAR4 Num_Accts
> VAR5 Zip_Code
>
> I need to go to my SAS data set above and replace the field
> names VAR1,...,VAR5 with
> Age, Income, Gender, Num_Accts, Zip_Code respectively. (A and
> B are the column headings in Excel sheet, not of importance,
> I guess.) Thanks.
as always: Why do you want to do this?
and then next Q:
do you want to rename or add labels?
*rename;
Data New;
set Old(rename = (Var1 = Age
...
) );
PROC SQL; select trim(OldName)
!! ' = '
!! trim(NewName)
into :List separated by ' '
from ListOfNames
;quit;
Data New;
set Old(rename = (&List.));
... hm 500 variables?
probably a lot of rows, too, eh?!
so use proc DataSets to do the rename:
just change the data structure, not read the entire data set.
you can use a similar list processing trick
to add labels:
label
Var1 = 'Age'
...;
watch those single and double quotes when you build :List
PROC SQL; select trim(OldName)
!! " = '"
!! trim(NewName)
!! "'"
... etc.
Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
|