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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.