BookmarkSubscribeRSS Feed
spraynardz90
Calcite | Level 5


Hi what is the command for renaming a set or column in dataset?

9 REPLIES 9
Alpay
Fluorite | Level 6

RENAME will rename a variable's name.

data x;

  set sashelp.class;

  rename Age=AgeNew;

run;

If you want to do it in an existing data set you may use PROC DATASETS; This will change the variable name without recreating the data set.

proc datasets lib=work;

  modify abc;

    rename oldvar=newvvar;

  run;

quit;

Ksharp
Super User

Plus,

Change Dataset name :

proc datasets lib=work;

    change oldTableName=newTableName;

quit;

Ksharp

spraynardz90
Calcite | Level 5

I'm not looking to rename the:

-whole data set

or a specfic variable within the data.

I am looking to rename the column title. ie: frequency count.

Alpay
Fluorite | Level 6

Then use LABEL statement.

proc datasets lib=work;

  modify abc;

    label oldvar="New Label";

  run;

quit;

spraynardz90
Calcite | Level 5

Capture.JPGThat doesn't seem to work.

Alpay
Fluorite | Level 6

You will need to use the column/variable name right after LABEL.

Frequency Count seems to the label associated with this column.

Right click on the column labeled Frequency Count and check out the name of the variable.

You can also use Proc Contents for this data set to figure out the column/variable names.

proc datasets lib=work;

  modify abc;

    label VariableName="New Variable Label";

  run;

quit;

spraynardz90
Calcite | Level 5

I see. Thank you very helpful.

It presents:

Name: COUNT

Label: Frequency Count

How do I rename the 'COUNT'. I need to perform 3 different counts and merge them back into the dataset. Everytime I perform the merge I only receive one COUNT column, rather than 3.

Alpay
Fluorite | Level 6

Use RENAME statement to rename the column.

Beware that when you change the column name the label of the column won't change.

proc freq data=sashelp.class;

  table Sex/out=class_summary;

run;

proc datasets lib=work nolist;

  modify class_summary;

    rename Count = New_Variable;

    label New_Variable = 'New Label';

  run;

quit;

ballardw
Super User

You can rename them while merging:

then change the label

data want;

     merge have1 (rename=(count=count1))

               have2 (rename=(count=count2))

               have3 (rename=(count=count3))

    ;

    by mergevariablename;

    label

          count1 ='Meaning of count1'

          count2 ='Meaning of count2'

          count3 ='Meaning of count3'

   ;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 3010 views
  • 1 like
  • 4 in conversation