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;
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.
The problem is it comes back and says I need a do statement and not sure what that means
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
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.
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.