BookmarkSubscribeRSS Feed
lalohg
Quartz | Level 8

Hi there,

I have a character variable with letters numbers and hyphen sign and would like to extract the letters and the first two digits before the FIRST hyphen sign and create a new variable identifying these people, here is an example

Variable ID looks like:

0165218-09
0165218-09
0165218-09
13-06-0290
SP131536-01
SP131536-01
0142135-02
0142135-02
0142135-02

The new variable will look like

13
SP
SP

all your help will be appreciated

Thank you

3 REPLIES 3
ballardw
Super User

Do you have any that start with one letter: S12345-67? Or one numeral then the hyphen: 1-234-456? If so how are these processed?

Steelers_In_DC
Barite | Level 11

The first two characters will be:

new_var = substr(variable,1,2)

I'm not sure what you are getting at with the hyphen.  If the hyphen is important for another reason you might have to use something in addition to this like scan().

lalohg
Quartz | Level 8

Thanks for your answers

ballardw: no, I don't have IDs starting with only one letter or one numeral

The IDs starting with SP indicate a type of affiliation (thanks Mark! I can identified these people now creating the new_var), those with two digits and then the hyphen have a different affiliation as those starting with numbers but with hyphen at the end like -01, -02 etc, but I still need to separate these latter two groups

Thanks again for your help

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 5466 views
  • 0 likes
  • 3 in conversation