BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
radha009
Quartz | Level 8

Can anyome help me with the code to extract a ticket number from  variable name ' Request item' , data is as below.

 

number Request_item

1            This request is part of UAT Ticket# RITM0157177

2            Commit result for UAT RITM0180513

 

 

Expected results

 

number    request_item                                                                                     ticket

1            This request is part of UAT Ticket# RITM0157177                            RITM0157177

2            Commit result for UAT RITM0180513                                                RITM0180513

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Try

  ticket = substr(x,FIND(x,'RITM'),11);

where X is the name of YOUR variable.

 

 

WARNING: This really only works reasonably well because RITM is an infrequent letter combination in English and the code is supposedly always in upper case. If the code letters at the start were more common such as AT even the upper case might be insufficient to find the ticket if billed to or for AT&T or any other organization with AT in their name or a person that uses those initials frequently. I am sure there are other cases to consider as well.

View solution in original post

7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
Is the ticket number ALWAYS in request_item? Is it ALWAYS the last piece of the string? Could there be text AFTER the ticket number? Does the ticket number ALWAYS start with RIT or RITM?

Cynthia
radha009
Quartz | Level 8
The ticket number is always in the request item. The text will be there before or after the ticket number. It always starts with RITM and 11 length.
shahparth260
Quartz | Level 8
  data have;
  	
  x="This request is part of UAT Ticket# RITM0157177";
  y="Commit result for UAT RITM0180513";

  run;


data want;
	 set have;

	 upx=strip(upcase(x));
	 upy=strip(upcase(y));

	 indx1=index(upx,"RITM");
	 indy1=index(upy,"RITM");

	 lenx1=length(substr(upx,x1));
	 leny1=length(substr(upy,y1));
	
	 subx=substr(upx,indx1,lenx1);
	 suby=substr(upy,indy1,leny1);

	 keep subx suby;
 run;

I can make it little shorter but I want to give idea for this that's why it's little long code 

 

I hope it helps

 

Thanks 

 

PS
shahparth260
Quartz | Level 8

Though Cynthia is absolutely  right with her questions for you but I give you just an idea

 

PS
nketata
Obsidian | Level 7

You have to extract the 11 last characters from Request_item column

 

DATA want; set have;

 ticket = substr(Request_item, length(Request_item)-11);run;

 

 

**I assume here the ticket number is always displayed at the end of Request_item***

radha009
Quartz | Level 8

No it will not be always end. it will any where

ballardw
Super User

Try

  ticket = substr(x,FIND(x,'RITM'),11);

where X is the name of YOUR variable.

 

 

WARNING: This really only works reasonably well because RITM is an infrequent letter combination in English and the code is supposedly always in upper case. If the code letters at the start were more common such as AT even the upper case might be insufficient to find the ticket if billed to or for AT&T or any other organization with AT in their name or a person that uses those initials frequently. I am sure there are other cases to consider as well.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1181 views
  • 0 likes
  • 5 in conversation