DATA Step, Macro, Functions and more

Extract a Category ID from a URL

Reply
New Contributor JFM
New Contributor
Posts: 4

Extract a Category ID from a URL

Hi,

I need to C.


The ID always follows “categoryId=” in the URL string and its always numbers.  I can’t use SCAN because the ID can be in a different place in the URL and is not always the same length .

URL
http://www.mywebsite.com/family/index.jsp?categoryId=61765546&cp=1766205&ab=en_US_MLP_SLOT_1_S1_SHOP
http://www.mywebsite.com/shop/index.jsp?categoryId=62593996&AB=en_US_HP_S2_Men_slot_1_S2_ShopNow
http://www.mywebsite.com/family/index.jsp?categoryId=62593846&cp=1766205&ab=ln_men_cs_thetrend:tropi...
http://www.mywebsite.com/family/index.jsp?categoryId=62594006&cp=1766205&AB=en_US_MLP_P_slot_10_S1_S...
http://www.mywebsite.com/family/index.jsp?categoryId=56906456
http://www.mywebsite.com/shop/index.jsp?categoryId=62593866&cp=1766205&ab=ln_men_cs_theshirt
http://www.mywebsite.com/family/index.jsp?categoryId=62593876&cp=1795710&AB=en_US_MLP__slot_2_S1_Sho...
http://www.mywebsite.com/shop/index.jsp?categoryId=57155616
http://www.mywebsite.com/shop/index.jsp?categoryId=1766618&ab=tn_women_golfandTennis&cp=17666


Again, its always the numbers which follow  "categoryId=" in the string. There may be other IDs in the URL which don't follow category ID so I need to make sure I'm not picking those up.  This is the output I'm looking for:


URLcategoryId
http://www.mywebsite.com/family/index.jsp?categoryId=61765546&cp=1766205&ab=en_US_MLP_SLOT_1_S1_SHOP61765546
http://www.mywebsite.com/shop/index.jsp?categoryId=62593996&AB=en_US_HP_S2_Men_slot_1_S2_ShopNow62593996
http://www.mywebsite.com/family/index.jsp?categoryId=62593846&cp=1766205&ab=ln_men_cs_thetrend:tropi...62593846
http://www.mywebsite.com/family/index.jsp?categoryId=62594006&cp=1766205&AB=en_US_MLP_P_slot_10_S1_S...62594006
http://www.mywebsite.com/family/index.jsp?categoryId=5690645656906456
http://www.mywebsite.com/shop/index.jsp?categoryId=62593866&cp=1766205&ab=ln_men_cs_theshirt62593866
http://www.mywebsite.com/family/index.jsp?categoryId=62593876&cp=1795710&AB=en_US_MLP__slot_2_S1_Sho...6259387
http://www.mywebsite.com/shop/index.jsp?categoryId=5715561657155616
http://www.mywebsite.com/shop/index.jsp?categoryId=1766618&ab=tn_women_golfandTennis&cp=17666181766618


Any assistance is greatly appreciated. Thanks!

Ask a Question
Discussion stats
  • 2 replies
  • 202 views
  • 0 likes
  • 3 in conversation