I have a text string and with length set and if the string is more than the length it gets truncated in middle. Can i handle such a way if it truncates a word in middle than replace it with "etc."
data inc; length text $200.; text="The man has a caregiver or an identified responsible person (for example, family member, social worker, case worker, or nurse) considered reliable by the nature in providing support to the headlines meeeting"; run;
This truncates -The man has a caregiver or an identified responsible person (for example, family member, social worker, case worker, or nurse) considered reliable by the nature in providing support to the headlines m
Can i replace "headlines m" with etc.. so that it makes some sense.
Any help on how to handle this
Hello, I think this should work
data inc;
length text $200. text196 txet $196.;
text="The man has a caregiver or an identified responsible person (for example, family member, social worker, case worker, or nurse) considered reliable by the nature in providing support to the headlines meeeting";
if length(text)>196 then do;
text=substr(text,1,197-index(reverse(substrn(text,1,196))," ") )||"etc.";
end;
run;
Bump up the length slightly:
data want;
length text $ 203;
text = " ........";
if length(text) > 200 then text = substr(text, 1, 195) || ' etc.';
run;
I cannot do as the length of the string should only be 200 and not more than that. so need to adjust the data
Hello, I think this should work
data inc;
length text $200. text196 txet $196.;
text="The man has a caregiver or an identified responsible person (for example, family member, social worker, case worker, or nurse) considered reliable by the nature in providing support to the headlines meeeting";
if length(text)>196 then do;
text=substr(text,1,197-index(reverse(substrn(text,1,196))," ") )||"etc.";
end;
run;
This will find the last blank from which it is possible to append the 'etc.' and don't cut a word in half right before it:
data want;
length newtext $200.;
text="The man has a caregiver or an identified responsible person (for example, family member, social worker, case worker, or nurse) considered reliable by the nature in providing support to the headlines meeeting";
newtext = text;
index = findc(newtext,' ','b');
if index > 195
then do;
newtext = substr(newtext,1,index);
index = findc(substr(newtext,1,index-1),' ','b');
end;
newtext = substr(newtext,1,index) !! 'etc.';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.