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

SAS group, 

 

         could you please help me get this from string name (3 spaces as delimiters, between name and city). I want to extract name. 

Any thoughts please. I have sas eg and it is not taking scan function (quotation marks has 3 spaces in between). It worked in SAS 9.3, but not in sas eg. 

example: name1=scan(name,1,"   ");

 have file 

name   city   state  zipcode

wal mart   siouxcity   ia  14525

arthur chiropracter nd   richmond   ca  25684

want file

wal mart

arthur chiropracter nd

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This is mildly clumsy, but it should work when you are searching for the beginning of the incoming string:

 

name1 = substr(name, 1, index(name, '   ') ) ;

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Are you reading an external file? If you actually have 3 characters between each field you could use the dlmstr='   ' option instead of dlm

 

However the data you show has only two spaces between the state and the zipcode so perhaps dlmstr='  ' (two spaces) will actually work to read the file.

 

Astounding
PROC Star

This is mildly clumsy, but it should work when you are searching for the beginning of the incoming string:

 

name1 = substr(name, 1, index(name, '   ') ) ;

 

buddha_d
Pyrite | Level 9
This works thanks Astounding

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5879 views
  • 1 like
  • 3 in conversation