- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all. Hopefully an easy question, for a Friday afternoon. A data set I read in has strings of numbers that look like this, this is one column in text format.
31.8 (29.7-33.9)
This is, for example, a rate and the confidence interval. i want to add a space before and after the dash, to make it look like this
31.8 (29.7 - 33.9)
Is this easy to do? Say the variable is "rate_ci".
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@geneshackman wrote:
Group Category rate low high rate_ci
Gender Male 31.4 28.5 34.4 31.4 (28.5-34.4)
Gender Female 31.4 29.1 33.7 31.4 (29.1-33.7)
Gender Female 31.5 24.4 38.6 31.5 (24.4-38.6)
Let's assume you are trying to show us what the dataset HAVE looks like. And that the last column in your listing is the variable name RATE_CI. So to create a new dataset named WANT with the corrected version of RATE_CI run code like this:
data want;
set have;
rate_ci = tranwrd(rate_ci,'-',' - ');
run;
Check the results and make sure that adding the two extra space characters didn't cause it to run out of room to store the full string. That is make sure the right parenthesis haven't disappeared in the new dataset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the Tranwrd Function
data _null_;
n = "31.8 (29.7-33.9)";
nn = tranwrd(n, "-", " - ");
put n = / nn =;
run;
Result:
n=31.8 (29.7-33.9) nn=31.8 (29.7 - 33.9)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please show a more representative example of your data.
@geneshackman wrote:
Ah, sorry, i didn't give enough information. It's not just this number, there are a bunch of numbers, all having the same format. I want to change them all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Gender Male 31.4 28.5 34.4 31.4 (28.5-34.4)
Gender Female 31.4 29.1 33.7 31.4 (29.1-33.7)
Gender Female 31.5 24.4 38.6 31.5 (24.4-38.6)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Gender Male 31.4 28.5 34.4 31.4 (28.5-34.4)
Gender Female 31.4 29.1 33.7 31.4 (29.1-33.7)
Gender Female 31.5 24.4 38.6 31.5 (24.4-38.6)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@geneshackman wrote:
Group Category rate low high rate_ci
Gender Male 31.4 28.5 34.4 31.4 (28.5-34.4)
Gender Female 31.4 29.1 33.7 31.4 (29.1-33.7)
Gender Female 31.5 24.4 38.6 31.5 (24.4-38.6)
Let's assume you are trying to show us what the dataset HAVE looks like. And that the last column in your listing is the variable name RATE_CI. So to create a new dataset named WANT with the corrected version of RATE_CI run code like this:
data want;
set have;
rate_ci = tranwrd(rate_ci,'-',' - ');
run;
Check the results and make sure that adding the two extra space characters didn't cause it to run out of room to store the full string. That is make sure the right parenthesis haven't disappeared in the new dataset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Best regards, Jos
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content