Hi All,
And Thank you for quick Response.
data have;
input error $200.;
cards;
1 LLLL MMMMM NNNN Missing0048165
2 LLLL MMMMM NNNN Missing
3 AAAAAA BBBBB CCCCCCCC segment Required0048158
4 AAAAAA BBBBB CCCCCCCC segment Required
5 XXXX YYYYYY ZZZZZZ (Required) Missing0000047
6 XXXX YYYYYY ZZZZZZ (Required) Missing
;
run;
From here - if data is ending with number need to remove the number
(if number is available on end of the data its not same and having differnt length)
output like
1 LLLL MMMMM NNNN Missing
2 LLLL MMMMM NNNN Missing
3 AAAAAA BBBBB CCCCCCCC segment Required
4 AAAAAA BBBBB CCCCCCCC segment Required
5 XXXX YYYYYY ZZZZZZ (Required) Missing
6 XXXX YYYYYY ZZZZZZ (Required) Missing
I would go for a regular expression, see below:
The \d idenifies digits, the + matches one or more times, the $ matches the position at the end of the input string
It is important to trim the string first
Hi,
Well, there are several options here:
Perl Regular expressions - This is probably the main options for string matching/replacing, however I foget the exact terminology now (prxparse, prxmatch etc)
Substr: Assuming the first number is zero (or a pattern) then you can do: substr(text,1,index(text,"0")-1);
String array: Just for fun this one:
data want;
set have;
do I=1 to length(text);
if substr(text,i,1) in ('0','1','2',...) then substr(text,i,1)=" ";
end;
run;
Thank u RW9,
But small correction from your code
I dont want remove any numbers from the data, which is, data ending with numbers like
3 AAAAAA BBBBB CCCCCCCC segment Required0048158 need to remove 0048158 only.(not any numbers from middle of the data)
Could you please help me to get it.
I would go for a regular expression, see below:
The \d idenifies digits, the + matches one or more times, the $ matches the position at the end of the input string
It is important to trim the string first
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.