Help using Base SAS procedures

Problem with label renaming

Reply
Contributor
Posts: 69

Problem with label renaming


I have a table that is as follows:

mem             admit                readmit                 sevcd                     sevdesc

1111                1                        0                        1                         minor

2222                1                        1                        1                         minor

3333                 1                       0                        2                         moderate

4444                1                        1                        2                         moderate

I want to rename mem to who as well as replace all those numbers with the word National. I want to keep all the other columns as they are. I tried this but it does not work right

data ntl (keep = admit readmit sevcd sevdesc);

set counts;

who = vname(national);

label = mem(who);

output;

end;

drop mem;

run;

Super User
Posts: 10,483

Re: Problem with label renaming

Syntax for renaming a variable is:

Rename oldvariablename = newvariablename

So it looks like you want RENAME MEM=WHO;

Your KEEP = variable list won't keep the new variable WHO though.

If you want all values of WHO to be "National" though it would be simpler to use:

WHO="National";

and add WHO to the keep list.

Contributor
Posts: 69

Re: Problem with label renaming

The problem is it comes back and says I need a do statement and not sure what that means


Contributor
Posts: 69

Re: Problem with label renaming

and the output needs to now look like this

who       admit          readmit         sevcd        sevdesc

national     1                 0                1             minor

national     1                 1                1             minor

national      1                0                2             moderate

national     1                 1                 2            moderate

Super User
Posts: 10,483

Re: Problem with label renaming

What do you mean the "Output" needs to look like this?

If you are worried about the order of columns in a dataset then:

data ntl (keep=who admit readmit sevcd sevdesc);

     who='National';

     set count;

run;

Personally, I don't worry about the column order in the data and work with what ever report procedure I'm using to control output order.

Contributor
Posts: 45

Re: Problem with label renaming

The original code contained an END; statement...that is why it is asking for a DO statement

You can use a LENGTH statement prior to the SET statement, to order your columns. Of course, PROC SQL works for this also, since you SELECT the variables and the order you want them to appear.

However, your REPORT/PRINT procedures will allow you to display the variables in any order.

Ask a Question
Discussion stats
  • 5 replies
  • 268 views
  • 0 likes
  • 3 in conversation