BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Nietzsche
Lapis Lazuli | Level 10

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?

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Kurt_Bremser
Super User

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.

Nietzsche
Lapis Lazuli | Level 10

note to myself:

PDV = Program Data Vector

SAS Base Programming (2022 Dec), Preparing for SAS Advanced Programming (Cancelled).
Patrick
Opal | Level 21

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;

Patrick_0-1665642409703.png

 

 

Tom
Super User Tom
Super User

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 391 views
  • 2 likes
  • 4 in conversation