Hello,
I basically have two values within a column that I need to add a space after a hyphen. Would a combination of find or regex expressions work here?.
data have;
input SUBJID $ INVNAM :$30.;
infile datalines dlm = '|';
datalines;
1001|Raman
1002|Rodgers
1003|Ekanayake-Bohlig
1004|Renczynska-Matysko
;
run;
data want;
input SUBJID $ INVNAM :$30.;
infile datalines dlm = '|';
datalines;
1001|Raman
1002|Rodgers
1003|Ekanayake- Bohlig
1004|Renczynska- Matysko
;
run;
Hi @smackerz1988 ,
You can replace the hyphen with a hyphen followed by a space, like this:
tranwrd(invnam, "-", "- ")
A regex expression is unnecessary in this case, but the code would look like this:
prxchange('s/-/- /', 1, invnam)
If you had more complex requirements, such as add a space only if the hyphen is after the first word or only if the hyphen is not at the end of the string, a regex expression would be more appropriate.
I hope that clarifies what @data_null__ meant.
Joshua
specifies a character constant, variable, or expression that you want to translate.
specifies a character constant, variable, or expression that is searched for in source.
Requirement | The length for target must be greater than zero. |
specifies a character constant, variable, or expression that replaces target. When the replacement string has a length of zero, TRANWRD uses a single blank instead.
But I want to add a space not replace the hyphen with a space
Hi @smackerz1988 ,
You can replace the hyphen with a hyphen followed by a space, like this:
tranwrd(invnam, "-", "- ")
A regex expression is unnecessary in this case, but the code would look like this:
prxchange('s/-/- /', 1, invnam)
If you had more complex requirements, such as add a space only if the hyphen is after the first word or only if the hyphen is not at the end of the string, a regex expression would be more appropriate.
I hope that clarifies what @data_null__ meant.
Joshua
Yes, it does thanks!
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.