Skip to main content
v2026.11,986 entries · CC-BY 4.0

Rename in SAS: Variables and Data Sets

Choose a SAS rename method by when the new name takes effect, then check variable names and values with a worked survey example.

Written and maintained by CASRAI Editorial Board

Published

On this page

To rename in SAS, use rename old_name=new_name; in a DATA step, or attach rename=(old_name=new_name) to a data set. The placement determines whether your code uses the old or new name during processing. Use PROC DATASETS to change names in an existing data set; use its CHANGE statement to rename the data set itself.

What it is used for in research

Renaming gives a variable a different identifier for subsequent programming. In a research data-preparation script, that can mean mapping an incoming survey field such as score_old to the analysis name score. The important decision is whether the new identifier should exist inside the current DATA step, only in its output, or in an already stored SAS member.

SAS documents those operations separately. A DATA-step RENAME statement supplies output variable names. An input RENAME= option makes the new names available for processing. A RENAME statement within PROC DATASETS changes the variables of the member selected by MODIFY. The identical word therefore has different contexts; copying the mapping without its surrounding statements can change the result.

Keep a mapping between incoming and analysis names alongside the preparation code. That is a practical way to make an illustrative transformation understandable: another analyst can see that score_old became score, rather than assuming a new measurement was calculated. The examples below distinguish renaming from a separate derived variable. For the surrounding program structure, see DATA steps and PROC steps in SAS.

Install or access

These examples use ordinary SAS DATA steps and Base SAS procedures. Start in a SAS environment available to you, and use a program editor to submit the code. There is no separate renaming package to install: the operations are part of the SAS statements, data set options and procedures documented in the sources.

For learning access, SAS documents a two-stage registration process for SAS OnDemand for Academics: create or use a SAS Profile, then register through welcome.oda.sas.com. Registered users have a SAS Studio link on their dashboard, and the browser must meet the service’s requirements. SAS recommends entering through that main site rather than bookmarking application links.

The service is a shared learning environment. Its FAQ says resource-intensive research workloads should use a private licensed environment instead. Use the fictional records below for practice; choosing an environment for an actual research project is a separate decision from learning the rename syntax.

Step-by-step task: rename SAS variables

The following records form an illustrative composite, not observations from a study. Run the setup first, then select the renaming approach that matches your task. Each mapping uses old_name=new_name; multiple mappings are separated by spaces.

  1. Create a small input and inspect its names. The input has three records, an identifier and two numeric fields. Keeping the input and output names distinct makes the effect of each example visible.
data work.survey_raw;
  input id score_old age_years;
  datalines;
101 12 34
102 18 41
103 15 29
;
run;

proc contents data=work.survey_raw varnum;
run;

PROC CONTENTS describes the data set and its variables. The VARNUM option requests their logical order rather than the usual alphabetical listing. Record the original names before changing them so that a failed mapping can be checked against the actual input.

  1. Rename variables in the output with a RENAME statement. Use this form when the current step should continue referring to the incoming names.
data work.survey_named;
  set work.survey_raw;
  rename score_old=score age_years=age;
  score_plus_one=score_old+1;
run;

The expression deliberately uses score_old. SAS writes that variable as score in work.survey_named, but the DATA-step declaration does not make score its processing name. The output also contains age and the separately calculated score_plus_one. This RENAME statement applies to every output data set from that DATA step, not just whichever output appears nearest to it.

  1. Rename on input when subsequent expressions need the new names. Put the option immediately after the input member in SET.
data work.survey_input_named;
  set work.survey_raw
      (rename=(score_old=score age_years=age));
  score_plus_one=score+1;
run;

Here score is available during DATA-step processing, so the expression uses it. Both examples produce the same intended analysis names and arithmetic, but they use different names inside the step. Choose one timing rule deliberately and carry it through every expression. This input option supplies names to this read operation; it does not permanently rename the variables in work.survey_raw.

  1. Rename only one output with an output data set option. Attach RENAME= to the output member instead of using the DATA-step statement.
data work.survey_output_named
     (rename=(score_old=score age_years=age));
  set work.survey_raw;
  score_plus_one=score_old+1;
run;

This is another output-time rename, so score_old remains the name used in the expression. The distinction becomes useful when a DATA step writes several outputs that need different naming conventions: the data set option applies to the member it follows, while the statement applies to all outputs. Do not expect placing the option near the start of the program to make it an input-time operation.

  1. Use renamed fields temporarily in a procedure. A procedure can accept the data set option even though the DATA-step RENAME statement is not a general PROC statement.
proc print data=work.survey_raw
     (rename=(score_old=score age_years=age)) noobs;
  var id score age;
  where score ge 15;
run;

The procedure uses score, including in the WHERE expression, because the input rename occurs before that processing. This example displays the fictional records with identifiers 102 and 103. It does not save a renamed copy of the input. If a later procedure reads work.survey_raw without the option, its variables still have the original names.

  1. Change an existing member’s variables with PROC DATASETS. First create the demonstration member, then use MODIFY to select it.
data work.survey_edit;
  set work.survey_raw;
run;

proc datasets library=work nolist;
  modify survey_edit;
  rename score_old=score age_years=age;
run;
quit;

This RENAME belongs to a MODIFY RUN group and changes the selected member’s variable names. It is a file-management operation, so the rename itself does not require a DATA step that reads and writes the observations. The initial DATA step above exists to give the example its own member to change.

Rename a SAS data set with CHANGE

To change the member name rather than a column name, use CHANGE within PROC DATASETS. The following code assumes step 6 has created work.survey_edit and that the new member name is available:

proc datasets library=work nolist;
  change survey_edit=survey_final;
run;
quit;

proc contents data=work.survey_final varnum;
run;

survey_final is now the member name used in subsequent references. Its variables remain the ones established by the preceding operation: id, score and age. Changing a member name and changing its variables are separate operations; a variable mapping is not a substitute for CHANGE.

Output and how to read it

Check the stored variable names with PROC CONTENTS and the record values with PROC PRINT. This separates a successful name change from an accidental change in data preparation. For example, after step 2:

proc contents data=work.survey_named varnum;
run;

proc print data=work.survey_named noobs;
  var id score age score_plus_one;
run;

The expected column names are id, score, age and score_plus_one. For identifiers 101, 102 and 103, the expected score values are 12, 18 and 15, while the derived field is 13, 19 and 16. Those are consequences of the fictional input and the explicit addition, not results from a research analysis.

A variable’s label is a separate attribute from its name. Do not use a familiar heading in a report as your only evidence that a rename succeeded. Inspect the variable identifier in the metadata, and inspect the actual member you intended to change. The PROC CONTENTS guide explains how to read the metadata report and save its output.

The downloadable data table below compares the scope, timing and syntax of the rename methods, including member renaming. It brings the separate SAS references together so that you can identify which object changes before choosing a command.

Troubleshooting

The new variable name is unavailable during the DATA step

Check where the rename is specified. With a DATA-step RENAME statement or output RENAME=, use the old name in the current step’s expressions. If the new name is needed during processing, attach RENAME= to the input member and use the new name consistently. Moving the statement above an expression does not change an output-time rename into an input-time rename.

KEEP= or DROP= conflicts with RENAME=

At the same data set option level, SAS applies KEEP= and DROP= before RENAME=. Use the old names in those options. This example retains the incoming fields first, renames two of them, then calculates with the new processing name:

data work.survey_kept;
  set work.survey_raw
      (keep=id score_old age_years
       rename=(score_old=score age_years=age));
  score_plus_one=score+1;
run;

Do not extrapolate that rule to every combination of statements and options. SAS separately documents a RENAME statement followed by an output KEEP= option: in that combination the output option uses the new names. Treat input options, DATA-step statements and output options as distinct stages.

PROC DATASETS reports a missing or occupied name

The old variable must exist in the member selected by MODIFY. The new name cannot already identify a variable or an index in that member. SAS documents an error when the old name is missing or the new variable name already exists. Inspect the current member and mapping before running the operation again; a previously completed rename can explain why an old name is now absent.

Indexes also matter. When a renamed variable has a simple index, SAS renames that index with it. A composite index references the new variable name, but its own name can still conflict with a proposed variable name. These rules are reasons to inspect metadata rather than assuming a data set is only a list of columns.

The source still has its original names

That is expected when the rename was applied while reading into a different output, or only within a procedure. Inspect the output member for DATA-step examples. For a deliberate change to an existing member, use the PROC DATASETS form and verify that member afterward. If only its name should change, select CHANGE instead.

Free alternatives

R and pandas offer column-renaming operations for their own data objects. They provide alternatives when a preparation workflow is being written in those languages. The table concerns naming operations only; it does not imply that SAS programs run unchanged in either environment.

Alternative Corresponding operation Scope and source
Base R Read or assign component names with names(); data-frame columns are named list components. R is Free Software under the GPL. R Core’s An Introduction to R documents names and data-frame structure.
Python with pandas df.rename(columns={'score_old': 'score'}, errors='raise') pandas is open source. Its API uses an old-to-new column mapping; errors='raise' reports missing keys.

For an existing R workflow, see renaming columns with base R and dplyr. In pandas, labels omitted from a mapping remain unchanged, so a partial mapping can target the columns that need new names. Keep the language’s mapping direction explicit: the pandas dictionary shown here uses a colon between the old and new labels, while SAS uses an equals sign.

Sources

Data: SAS rename methods by target and timing

Original cross-reference of SAS DATA-step statements, data set options and DATASETS procedures. Compiled from the official references to separate output naming, input-time naming, procedure-local naming, existing-variable changes and member-name changes. Syntax cells are schematic fragments; see the guide for complete examples.

SAS rename methods by target and timing
MethodTargetWhen the new name appliesSyntax fragmentOfficial source
DATA-step RENAME statementVariables in all DATA-step outputsOn output; expressions in that step use old namesrename old=new;https://documentation.sas.com/api/collections/pgmsascdc/v_065/docsets/lestmtsref/content/lestmtsref.pdf?locale=en
Input RENAME= optionVariables read from a specified input memberBefore DATA-step processing; expressions use new namesset source(rename=(old=new));https://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/p09ikb01zz9knnn16y401utyq4un.htm
Output RENAME= optionVariables in a specified output memberOn output; expressions in that step use old namesdata target(rename=(old=new));https://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/p09ikb01zz9knnn16y401utyq4un.htm
Procedure input RENAME= optionVariables as used by that procedureBefore procedure processing; WHERE uses the new nameproc print data=source(rename=(old=new));https://support.sas.com/documentation/cdl/en/ledsoptsref/69751/HTML/default/p09ikb01zz9knnn16y401utyq4un.htm
DATASETS MODIFY and RENAMEVariables in an existing memberChanges the selected stored membermodify member; rename old=new;https://documentation.sas.com/api/docsets/proc/9.4/content/proc.pdf?locale=en
DATASETS CHANGESAS file/member name in the same libraryChanges the stored member namechange old_member=new_member;https://documentation.sas.com/api/docsets/proc/9.4/content/proc.pdf?locale=en

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Rename in SAS: Variables and Data Sets

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →