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, ' ') ) ;
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.
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.