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

I have a dataset in which I am trying to create multiple columns from one column basis on text for eg:-

 

DateCustomerAddressVch TypeVch No.DebitNarration
03.04.2019Hasan pvt ltdPlot no 05, Tilak road New delhi, DelhiSalesBPL/AT/0012336374.00Being the Sale of Cut Ornge Grade:"APTC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.
03.04.2019Indra pvt ltd112, Nelson road, DelhiSalesBPL/OT/0023336374.00Being the Sale of Cut Apple Grade:"ORTC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.
03.04.2019Middle Venture5th Floor, Tamouh Tower, Marina Square, Al Reem Island Abu Dhabi United Arab EmirateSalesBPL/PT/0032436375.00Being the Sale of Cut Pineapple Grade:"PATC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.

 

now on the basis of narration I am trying to create new column for eg:-

DateCustomerAddressVch_TypeVch_NoDebitNarrationGradeInvoiceqty AmountExch_Rate
03.04.2019Hasan pvt ltdPlot no 05, Tilak road New delhi, DelhiSalesBPL/AT/0012336374.00Being the Sale of Cut Ornge Grade:"APTC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.APTC/I/66BPL/CA/001/2019-2012430 Kgs$.34182.50.00Rs.68.35
03.04.2019Indra pvt ltd112, Nelson road, DelhiSalesBPL/OT/0023336374.00Being the Sale of Cut Apple Grade:"ORTC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.ORTC/I/66BPL/CO/001/2019-2012430 Kgs$.34182.50.00Rs.68.35
03.04.2019Middle Venture5th Floor, Tamouh Tower, Marina Square, Al Reem Island Abu Dhabi United Arab EmirateSalesBPL/PT/0032436375.00Being the Sale of Cut Pineapple Grade:"PATC/I/66" Blend Cut apple vide Invoice No.BPL/CT/001/2019-20 Dt.03.04.2019 - Qty.12430 Kgs for - $.34182.50.00 Exch.Rate:Rs.68.35.PATC/I/66BPL/CP/001/2019-2012430 Kgs$.34182.50.00Rs.68.35

 

I have tried using substr and scan function but it not giving me the result because words count and delimiter's are not same

Please help me on this.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Duggins
Obsidian | Level 7

I had effectively the same approach as above, but I would probably nest all the position information unless you need to save that information. The ones below should work as long as the data you have follows the style shown in your original post. I did use two steps for Exchange Rate so that the code wasn't as wide when posting it.

grade = scan(substr(narration, index(narration,'Grade:')+6),1,'"');
invoice = scan(substr(narration, index(narration,'No.')+3),1,' ');
qty = input(scan(substr(narration, index(narration,'Qty.')+4),1,' '),best12.);
Amount = scan(substr(narration,index(narration,'$')),1,' ');
_ER = scan(substr(narration, index(narration,'Rate')+4),1,':');
ExchRate = substr(_ER,1,length(_ER)-1);

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Find where the text Grade: is in the variable called Narration, then take the next word where the delimiters are double quotes

 

Example

 

where = findw(narration,'Grade:');
grade = scan(substr(narration,where+6),1,'"');

  

--
Paige Miller
Duggins
Obsidian | Level 7

I had effectively the same approach as above, but I would probably nest all the position information unless you need to save that information. The ones below should work as long as the data you have follows the style shown in your original post. I did use two steps for Exchange Rate so that the code wasn't as wide when posting it.

grade = scan(substr(narration, index(narration,'Grade:')+6),1,'"');
invoice = scan(substr(narration, index(narration,'No.')+3),1,' ');
qty = input(scan(substr(narration, index(narration,'Qty.')+4),1,' '),best12.);
Amount = scan(substr(narration,index(narration,'$')),1,' ');
_ER = scan(substr(narration, index(narration,'Rate')+4),1,':');
ExchRate = substr(_ER,1,length(_ER)-1);

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 758 views
  • 2 likes
  • 3 in conversation