LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 1998, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 13 Mar 1998 10:03:14 -0500
Reply-To:   mdmiller@syr.edu
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   "Mark D. H. Miller" <mdmiller@SYR.EDU>
Organization:   Syracuse University, FACSS
Subject:   Re: Splitting a variable into two variables based on a character somewhere in the field
Comments:   To: Jim Linck <jim.linck@ASU.EDU>
Content-Type:   text/plain; charset=us-ascii

Jim Linck wrote: > > Seems like the pointer, input and substring commands may be able to be used > together to handle this task; however, I'm not sure how to do it. > > I have a Name which I read in originally as part of an overall .csv file. > The name is in the format last, first. What I want to do is create two > variables from the Name variable, last and first where last contains all > info before the command and first contains all info after the comma. > Anybody know how to do that? > > Thanks.

Use the SCAN function. which separates a character expression into words and returns the Nth word SCAN( argument, n <,delimiters> ) where argument is a valid SAS character expression, n is a valid SAS numeric expression, and delimiter is the character(s) you wish to use to delimit words.

If delimiter is omitted, the following are treated as delimiters (on ASCII systems) blank . < + | & ! $ * ) ; ^ / , % > \

Since you are parsing a name which could have embedded periods, to explicitly follow the rule you describe would require

username= 'lastname, firstname' ; *sample data;

lname = scan(username,1,','); fname = scan(username,2,',');

-- *-------------------------------------------------------------* Mark D. H. Miller <mdmiller@syr.edu> Faculty Computing and Media Services Tel: 315.443-2143 272 Newhouse Communications Center II Fax: 315.443-5658 Syracuse University Syracuse, NY 13244-2110 *-------------------------------------------------------------*


Back to: Top of message | Previous page | Main SAS-L page