Hi there,
I am trying to extract part of a string available between 3rd and 4th pipe. Can anybody please assist me to move forward.
data HAVE;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 ABC|X01|X02|2001|DEF
102 ABC|X001|X002|2002|DEF
103 ABC|X0001|X0002|2003|DEF
104 ABC|X00001|X00002|2004|DEF
105 ABC|X01|X02|2005|DEF
;
RUN;
data WANT;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 2001
102 2002
103 2003
104 2004
105 2005
;
RUN;
Thank you in advance for your kind guidance.
Regards,
data HAVE;
length id $3 comment $50 ;
input id comment $ ;
want=scan(comment,-2,'|');
datalines;
101 ABC|X01|X02|2001|DEF
102 ABC|X001|X002|2002|DEF
103 ABC|X0001|X0002|2003|DEF
104 ABC|X00001|X00002|2004|DEF
105 ABC|X01|X02|2005|DEF
;
RUN;
Hi Ksharp,
can you kindly help me to extend this code to count the position of PIPE from ABC. As ABC segment may be preceded by other string. My target is to extract content available between 3rd and 4th pipe from the term ABC.
data HAVE;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 X01|X02|ABC|X01|X02|2001|DEF
102 X01|X02|X02|ABC|X001|X002|2002|DEF
103 X01|X02|ABC|X0001|X0002|2003|DEF
104 X01|X02|X02|ABC|X00001|X00002|2004|DEF
105 X01|X02|ABC|X01|X02|2005|DEF
;
RUN;
data WANT;
length id $3 comment $50 ;
input id comment $ ;
datalines;
101 2001
102 2002
103 2003
104 2004
105 2005
;
RUN;
Once again thanks for your kind response.
You could use the SCAN() function.
comment=scan(comment,4,'|');
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: