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 (July 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 20 Jul 2007 08:51:43 -0400
Reply-To:     Nathaniel.Wooding@DOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject:      Re: Selecting all but the first word from a character variable
Comments: To: pburgess@FILCS.COM
In-Reply-To:  <1184935442.461700.314980@n60g2000hse.googlegroups.com>
Content-Type: text/plain; charset="US-ASCII"

Paul

Try the following which uses the INDEXC function to find the location of the first underscore.

data test; length var_name $25; input var_name $; where=indexc(var_name,'_'); rest=substr(var_name,where+1); drop where; datalines; mary_fred_harry george_sue_henry_kay_mary sue_kim ; run; proc print; run;

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

pburgess@FILCS.CO M Sent by: "SAS(r) To Discussion" SAS-L@LISTSERV.UGA.EDU <SAS-L@LISTSERV.U cc GA.EDU> Subject Selecting all but the first word 07/20/2007 08:44 from a character variable AM

Please respond to pburgess@FILCS.CO M

Dear All

I have a character variable consisting of varying numbers of words separated by underscores.

I wish to create a new variable that consists of all but the first word of this variable, words again separated by underscores.

>From the dataset below I wish to create variable new_var, with values:

fred_harry sue_henry_kay_mary kim

Your help would be appreciated.

Paul

data test; length var_name $25; input var_name $; datalines; mary_fred_harry george_sue_henry_kay_mary sue_kim ; run;

----------------------------------------- CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and/or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.


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