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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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