In the textbook (Elliot - SAS essentials pg), it showed us two ways of renaming variable(s).
Method 1, with parenthesis
DATA NEW; SET TRANSPOSED (RENAME (INFO1=T1 INFO2=T2 INFO3=T3 INFO4=T4 INFO5=GENDER)); RUN;
Method 2, without parenthesis
DATA NEW; SET TRANSPOSED; RENAME INFO1=T1 INFO2=T2 INFO3=T3 INFO4=T4 INFO5=GENDER;
RUN;
Is there any reason to used one method over the other one? or they are both equal in the eyes of SAS programming?
The dataset option allows renaming for each individual dataset (SET and MERGE allow multiple datasets) before the PDV is built, while the RENAME statement works in the context of the PDV.
The dataset option allows renaming for each individual dataset (SET and MERGE allow multiple datasets) before the PDV is built, while the RENAME statement works in the context of the PDV.
note to myself:
PDV = Program Data Vector
Oh yes, PDV is such a common acronym among SASians that we often overlook it may be confusing to beginners.
For your method 1 the correct syntax needs to include an equal sign.
DATA NEW; SET TRANSPOSED (RENAME=(INFO1=T1 INFO2=T2 INFO3=T3 INFO4=T4 INFO5=GENDER)); RUN;
Those are not really equivalent.
The equivalent code using the RENAME= dataset option would be with the option on the output dataset.
The way you have it the names of the variables during the execution of the data step will be the NEW names.
You can use the RENAME= option in other code than data steps, such as PROC steps.
In general you should only use the RENAME= dataset option when you NEED to use it.
Here is an example where you need to use the RENAME= dataset option. There was a recent question where someone needed to match FID in one dataset to FAMID in another dataset. You could use the RENAME= dataset option on one of the input datasets to make that happen.
data want;
merge dads(rename=(fid=famid)) kids;
by famid;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.