- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm trying to figure out how to replace the spaces within the Init variable with dashes ("-"). I've already compressed the variable to remove the periods from the raw data (3rd pic below), but just need the final initial format to be in FML or F-L if missing data. Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The TRANSLATE() function is for replacing characters with other characters. Watch out for two things. Remember to trim the trailing blanks from your variable's value. And the arguments for TRANSLATE() are in the opposite order of what you normally expect.
data want;
set have;
myvar = translate(trim(myvar),'-',' ');
run;
PS Please post text as text, not as photographs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If your variable is numeric you can apply the format directly to get the desired displayed value.
https://documentation.sas.com/?cdcId=vdmmlcdc&cdcVersion=1.0&docsetId=leforinforref&docsetTarget=n1s...
The process for INITS is similar to what you've done with SSN, but you can use COUNTC() or LENGHT to count the number of periods/letters to deal with the two versus three letter cases.
inits_new = compress(inits);
if length(inits_new) = 2 then inits_new = catx('-', char(inits_new, 1), char(inits_new, 2));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can you copy and paste the text of the code in a reply? This isn't legible when I zoom.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The TRANSLATE() function is for replacing characters with other characters. Watch out for two things. Remember to trim the trailing blanks from your variable's value. And the arguments for TRANSLATE() are in the opposite order of what you normally expect.
data want;
set have;
myvar = translate(trim(myvar),'-',' ');
run;
PS Please post text as text, not as photographs.