BookmarkSubscribeRSS Feed
tmcrouse
Calcite | Level 5


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;

5 REPLIES 5
ballardw
Super User

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.

tmcrouse
Calcite | Level 5

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


tmcrouse
Calcite | Level 5

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

ballardw
Super User

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.

Jay_TxOAG
Quartz | Level 8

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.

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
  • 5 replies
  • 849 views
  • 0 likes
  • 3 in conversation