I am trying to extract the middle 2 numbers from the group names below:
I applied the formula below; however, I am getting an error.
Here is one way:
data have; informat groupname $15.; input groupname; want=substr(groupname,anydigit(groupname)+2,2); cards; VIPER170891 HEAT170992 BULLS170691 ;
Art, CEO, AnalystFinder.com
Here is one way:
data have; informat groupname $15.; input groupname; want=substr(groupname,anydigit(groupname)+2,2); cards; VIPER170891 HEAT170992 BULLS170691 ;
Art, CEO, AnalystFinder.com
Thank you for your help; It worked !
After posting my suggestion, I noticed that your initial code looked like it was pulled from a proc sql instance. If so, the following would work:
data have;
informat groupname $15.;
input groupname;
cards;
VIPER170891
HEAT170992
BULLS170691
;
proc sql;
create table want as
select substr(t1.groupname,anydigit(groupname)+2,2) as want
from have t1
;
quit;
Art, CEO, AnalystFinder.com
if your pattern holds true for all obs
data have;
informat groupname $15.;
input groupname;
want=reverse(substr(reverse(strip(groupname)),3,2));
cards;
VIPER170891
HEAT170992
BULLS170691
;
/*if reading a dataset*/
data have;
informat groupname $15.;
input groupname;
cards;
VIPER170891
HEAT170992
BULLS170691
;
data want;
set have;
want=reverse(substr(reverse(strip(groupname)),3,2));
run;
Another way, this 'kd' thing was shared by Art to me only yesterday 🙂
data have;
informat groupname $15.;
input groupname;
cards;
VIPER170891
HEAT170992
BULLS170691
;
data want;
set have;
want=substr(compress(strip(groupname),'','kd'),3,2) ;
run;
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.