BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Guerraje
Quartz | Level 8

Hello, 

 

I am working with a data set of county names. Some have underscores such as Kit_Carson and I want to replace the _ with a regular space so that it reads (Kat Carson). I need to remove all underscores in the entire data set. I am unsure of how to complete this step. I just transposed my data from wide to long, and now trying to remove the _. I think I can do this in the tranwrd step, but when searching this topic I can only find the opposite of what I need so I am looking for some guidance here. This is what my code I am working with looks like what what I am trying to create. 

Thank you! 

 

 

 

PROC TRANSPOSE DATA = fixedcounty OUT= names;
var county:;
run;

data names;
set names;
county=tranwrd(_name_,"county", "");
run;

proc contents data=fixedcounty varnum;
run;
proc print data=fixedcounty;
run;
proc print data= names;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

 

 

I think you want something that looks more like

 

   my_new_county = tranwrd(county,"_", " ");

View solution in original post

2 REPLIES 2
HB
Barite | Level 11 HB
Barite | Level 11

 

 

I think you want something that looks more like

 

   my_new_county = tranwrd(county,"_", " ");
Tom
Super User Tom
Super User

So you have variable named COUNTY that contains values like 'Kit_Carson'?

You can use the TRANSLATE() function to replace characters with other characters.

data want;
  set have;
  county=translate(county,' ','_');
run;

I am not sure how PROC TRANSPOSE is supposed to help you.  If you have multiple COUNTY variables then use an ARRAY.

data want;
  set have;
  array vars county: ;
  do over vars;
    vars=translate(vars,' ','_');
  end;
run;