Date: Thu, 30 Aug 2007 14:10:36 -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: How to cut a text string ??
In-Reply-To: <c2192a610708301055m1814b5ebua8fdf0188da2d475@mail.gmail.com>
Content-Type: text/plain; charset="US-ASCII"
In that case, try
Data test;
infile cards missover;
Input var1 $50. ;
cards;
THE MAN IS ON THE HILL HAS TO CLIMB DOWN SLOWLY
;
Run ;
data need (keep=var2);
length var2 $ 50 ;
set test;
words = length(var1) - length(compress(var1)) +1;
do i = 1 to ceil(words/3);
var2 = cat(scan(var1,1),' ',scan(var1,2),' ',scan(var1,3));
output;
var1 = left(substr(var1,1+length(var2)));
end;
run;
proc print data = need;
run;
Nat Wooding
Environmental Specialist III
Dominion, Environmental Biology
4111 Castlewood Rd
Richmond, VA 23234
Phone:804-271-5313, Fax: 804-271-2977
SAS_learner
<proccontents@GMA
IL.COM> To
Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU
Discussion" cc
<SAS-L@LISTSERV.U
GA.EDU> Subject
Re: How to cut a text string ??
08/30/2007 01:55
PM
Please respond to
SAS_learner
<proccontents@GMA
IL.COM>
My bad I forgot to tell you I am still using sas v8
thanks
On 8/30/07, Jack Clark <JClark@chpdm.umbc.edu> wrote:
>
> Will this work?
>
> Data test;
> infile cards missover;
> Input var1 $50. ;
> cards;
> THE MAN IS ON THE HILL HAS TO CLIMB DOWN SLOWLY
> ;
> Run ;
>
>
> data need (keep=var2);
> length var2 $ 50 ;
> set test;
> do i = 1 to ceil(countw(var1)/3);
> var2 = cat(scan(var1,1),' ',scan(var1,2),' ',scan(var1,3));
> output;
> var1 = left(substr(var1,1+length(var2)));
> end;
> run;
>
> proc print data = need;
> run;
>
>
> Jack Clark
> Research Analyst
> Center for Health Program Development and Management
> University of Maryland, Baltimore County
>
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> SAS_learner
> Sent: Thursday, August 30, 2007 12:54 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: How to cut a text string ??
>
> Hello guys,
>
> I know something like has been asked before or done before but I could
> not
> find it in earlier Postings, what I need to do is count number of words
> in
> a line and after 3rd word ( This is for now may change later ) I need to
> break the line and make it as new Record . For example
> I have a variable called Comment
>
> Data test ;
> Input Comment $100.
> Datalines;
> THE MAN IS ON THE HILL HAS TO CLIMB DOWN SLOWLY
> ;
> Run ;
> You see that Comment is one big line but I need to put in data set in a
> such
> a way
> Data test ;
> Input Comment $100.
> Datalines;
> THE MAN IS
> ON THE HILL
> HAS TO CLIMB
> DOWN SLOWLY
> ;
> Run ;
>
> I am doing this Just for a Listing sake and there there of lot other
> variables along with it , If anybody earlier did some thing similar can
> you
> share that macro with me
>
> thanks
>
-----------------------------------------
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.
|