Help using Base SAS procedures

rename column in data step

Accepted Solution Solved
Reply
Regular Contributor
Regular Contributor
Posts: 238
Accepted Solution

rename column in data step

data chi (drop = no yes rename=tin=who);

set tax;

array _col(2) no yes;

do _n_=1 to 2;

admission = vname (_col(_n_));

count = _col(_n_);

output;

end;

run;

It does not change my column named tin to name it who instead. everything else works great.


Accepted Solutions
Solution
‎03-14-2012 06:14 PM
Super User
Posts: 17,823

rename column in data step

You might still see the name 'tin' because the label assigned to the variable 'who' is 'tin'.

try the following with all labels removed. Or just right click the variable and check the properties.

data chi (drop = yes no RENAME=(TIN=WHO));

set tax;


attrib _all_ label='';


array _col(2) no yes;

do _n_=1 to 2;

admission = vname (_col(_n_));

count = _col(_n_);

output;

end;

run;

View solution in original post


All Replies
Regular Contributor
Posts: 233

rename column in data step

data chi (drop = yes no RENAME=(TIN=WHO));

set tax;

array _col(2) no yes;

do _n_=1 to 2;

admission = vname (_col(_n_));

count = _col(_n_);

output;

end;

run;

Regular Contributor
Regular Contributor
Posts: 238

rename column in data step

Hum. That did not work. It is still named TIN

Solution
‎03-14-2012 06:14 PM
Super User
Posts: 17,823

rename column in data step

You might still see the name 'tin' because the label assigned to the variable 'who' is 'tin'.

try the following with all labels removed. Or just right click the variable and check the properties.

data chi (drop = yes no RENAME=(TIN=WHO));

set tax;


attrib _all_ label='';


array _col(2) no yes;

do _n_=1 to 2;

admission = vname (_col(_n_));

count = _col(_n_);

output;

end;

run;

Respected Advisor
Posts: 3,124

rename column in data step

When you just have one variable to rename, parenthesis is not must to have, your original code should work.

My guess is that the variable name has already been changed, however, the label is still 'tin'.  When you open in explorer, it still shows the original label name. Find out the answer by double click the variable name or use proc print, proc contents.

Regards,

Haikuo

PROC Star
Posts: 7,363

rename column in data step

Haikuo: A second thing I learned this week!  And it is only Wednesday!  I'm still going to use parentheses in my own recode statements, as I know it will ALWAYS work regardless of the number of variables being recoded, but I never knew that you didn't need them for just one recode.

Respected Advisor
Posts: 3,124

rename column in data step

Art, if I have to  count how many SAS stuff that I have learned directly from you, I would need a counter that at least supports 3 digits. :smileysilly:. BTW, what was the first thing if you don't mind sharing?

Haikuo

PROC Star
Posts: 7,363

rename column in data step

Haikuo: Howard's use of imbedding _numeric_ and _character_ in variable lists.  e.g.:

proc print data=sashelp.class;

  var name-numeric-weight;

run;

Hey, I've been trying to learn this language for 38 years now and, almost every week, still learn something I didn't know.

Respected Advisor
Posts: 3,124

Re: rename column in data step

Thanks, Art! And Howard! This is so COOL!

Super User
Posts: 17,823

Re: rename column in data step

Am I missing something or do the following produce the exact same output?

What was the first one supposed to do?

proc print data=sashelp.class;

  var name-numeric-weight;

run;

proc print data=sashelp.class;

  var _numeric_;

run;

PROC Star
Posts: 7,363

Re: rename column in data step

Fareeza,  My fault!  I unsuccessfully tried to copy and paste from a previous post.  Try the following:

proc print data=sashelp.class;

  var name _numeric_;

run;

proc print data=sashelp.class;

  var _numeric_;

run;

Super User
Posts: 17,823

Re: rename column in data step

That makes way more sense! ThanksSmiley Happy

Super Contributor
Posts: 1,636

Re: rename column in data step

Hi Art,

I thought you wanted to show how to print all numeric or character variables between two variables. In the example below, the two outputs are different.  Thanks -Linlin

data class;

  set sashelp.class;

  age2=age;

  w2=weight;

proc print data=class;

title print out all numeric variables;

var _numeric_;

run;

proc print data=class;

title print out all numeric variables between name and weight;

  var name-numeric-weight;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 358 views
  • 0 likes
  • 6 in conversation