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.
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, ' ') ) ;
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.
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, ' ') ) ;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.