Please show what you want as I have no idea at this point what the goal of this process is.
If you want to change the name of COL1 to FRED then RENAME is the way to go.
Why would it work any differently than what you did for numeric variables?
For the numeric I was using Scan to create the name but for the character I had to use rename, as you suggested. Thank you so much for your (and everyone's) help. I know there were a lot of messages back and forth but they really help me see what I am doing incorrectly. It is extremely helpful to have someone with extensive knowledge to look through the issues and suggest different ways to work with them. I learn a lot this way. I use these topics a lot in this board and I usually find the answers I need, which is great. When I don't and I post mine, all of you are amazing! It is an amazing learning process you can't get anywhere else.
It does not look like I need the suffix. I will only use the rename option ! Thank you so much. It is much appreciated.
To update how I ended up solving this, after everyone's help. Thank you all again.
I used
proc transpose
data=have
out=long (
where=(col1 ne 0)
)
;
by obs;
var med:;
run;
data want;
set long;
med = scan(_name_,-1,"_");
drop _name_ col1;
run;
and replaced col1 ne 0 with col1 ne ' ' for the character variables and use RENAME col 1 in the data step for character variables instead of scan.
Data want2 (rename=(col1=mycharactervarname));
set long;
Run;
I transposed each variable separately and then merged them all. I have not done the date variables yet, but it should be straightforward. I used col2 to check for duplicates in my data file (before dropping it) and found out which ones they were and removed them from my have file (as when this happens, it indicates a data collection mistake in this case). I hope this can help others as well.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.