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

I want to fetch variable values ,if first letter of variable value is digit then that digit should be omitted and want to fetch values.

varible:

ram

lakshman

manhor1

1hello

2hai

fetched varible:

ram

lakshman

manohar1

hello

hai

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select case when input(substr(name,1,1),8.)>=0 then compress(name,,'ka') else name end as fetched_name

from have;

quit;

View solution in original post

6 REPLIES 6
stat_sas
Ammonite | Level 13

proc sql;

create table want as

select case when input(substr(name,1,1),8.)>=0 then compress(name,,'ka') else name end as fetched_name

from have;

quit;

Reeza
Super User

If this is in EG Query builder you'll need an advanced expression.

Substr out the first character and use the anydigit function 

If this was a data step:

data want;

set have;

first_char=substr(variable, 1,1);

if anydigit(first_char) then fetched_variable=substr(variable, 2);

else fetched_variable=variable;

run;

Jagadishkatam
Amethyst | Level 16

Please try PRX

proc sql;

create table want as select variable,

case when prxmatch('/\d{1}/',variable)^=1 then variable

else  compress(variable,,'ka') end as variable2 from have;

quit;

Thanks,

Jag

Thanks,
Jag
slchen
Lapis Lazuli | Level 10

data want;

set have;

fetched_variable=prxchange('s/^\d{1}(.)/$1/',-1,variable);

run;

proc sql;

select prxchange('s/^\d{1}(.)/$1/',-1,variable) as fetched_variable from have;

quit;

rajeshm
Quartz | Level 8

hi,

thanks.

instead of the input(substr(name,1,1),8.)>=0,we  can use notdigit(substr(name,1,1)) --easy to understand .

stat_sas
Ammonite | Level 13

Hi,

Yes, this is a better way to do that. I think notalpha(substr(name,1,1)) will be used instead of notdigit(substr(name,1,1)) to get the desired results.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 6 replies
  • 1297 views
  • 0 likes
  • 5 in conversation