Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Challenging? Search Text File and Concatenate Rows
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Lewis Jordan  
View profile  
 More options May 11 2008, 3:28 pm
Newsgroups: comp.soft-sys.sas
From: lewj...@UGA.EDU (Lewis Jordan)
Date: Sun, 11 May 2008 15:28:29 -0400
Local: Sun, May 11 2008 3:28 pm
Subject: Challenging? Search Text File and Concatenate Rows
Generous SAS Users:

I am finding this problem quite challenging. I want to scan rows of a text file for a "Primary Key" word (or symbol). When I find the "Primary Key", I want to concatenate the ENTIRE line the "Primary Key" word appeared on with all rows underneath it until I find another, "Secondary Key" word. Consider the snippet below. The "Primary Key" = TEST, the "Secondary Key" = !

data test;
input line $ 50.;
cards;
This is a TEST.
Can you help!
I want to write SAS code that
scans each line and picks out the word TEST!
The program should search each line for
the word TEST and then concatenates the
following lines until it reaches
the exclamation symbol!
;
proc print;
run;quit;

The result would be 3 lines:

1)This is a TEST. Can you help!
2)scans each line and picks out the word TEST!
3)the word TEST and then concatenates the following lines until it reaches the exclamation symbol!

Thanks for all your help!!!!

Lewis


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"data _null_,"  
View profile  
 More options May 11 2008, 5:19 pm
Newsgroups: comp.soft-sys.sas
From: datan...@GMAIL.COM ("data _null_,")
Date: Sun, 11 May 2008 16:19:05 -0500
Local: Sun, May 11 2008 5:19 pm
Subject: Re: Challenging? Search Text File and Concatenate Rows
data test;
   infile cards;
   input;
   length string $256;
   retain string ' ' start 0;
   if indexW(_infile_,'TEST',' !.') then do;
      start=1;
      call missing(string);
      end;
   if start then string = catx(' ',string,_infile_);
   if index(_infile_,'!') then do;
      start = 0;
      output;
      end;
   cards;
This is a TEST.
Can you help!
I want to write SAS code that
scans each line and picks out the word TEST!
The program should search each line for
the word TEST and then concatenates the
following lines until it reaches
the exclamation symbol!
;
proc print;
run;quit;

On 5/11/08, Lewis Jordan <lewj...@uga.edu> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sigurd Hermansen  
View profile  
 More options May 11 2008, 11:38 pm
Newsgroups: comp.soft-sys.sas
From: HERMA...@WESTAT.COM (Sigurd Hermansen)
Date: Sun, 11 May 2008 23:38:16 -0400
Local: Sun, May 11 2008 11:38 pm
Subject: Re: Challenging? Search Text File and Concatenate Rows
I've presumed to make a few changes to a generous solution to a
cleverly-presented problem:
data test (keep=string);
   infile cards;
   input;
   length string $256;
   retain string ' ' start 0;
   if indexW(_infile_,'TEST',' !.') then do;
      start=1;
      call missing(string);
      end;
   if start then string = catx(' ',string,_infile_);
   if index(_infile_,'!') then do;
      if start ^= 0 then output;
      start = 0;
      end;
   cards;
This looks like homework!!!!!
This is a TEST.
Can you help!
I want to write SAS code that
scans each line and picks out the word TEST!
The program should search each line for
the word TEST and then concatenates the
following lines until it reaches
the exclamation symbol!
;
proc print noobs;
run;quit;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
"Keintz, H. Mark"  
View profile  
 More options May 11 2008, 11:13 pm
Newsgroups: comp.soft-sys.sas
From: mkei...@WHARTON.UPENN.EDU ("Keintz, H. Mark")
Date: Sun, 11 May 2008 23:13:33 -0400
Local: Sun, May 11 2008 11:13 pm
Subject: Re: Challenging? Search Text File and Concatenate Rows
Lewis:

I think this is an excellent case for a paired DO UNTIL and DO WHILE as
below.  Also, since you said "concatenate", I literally concatenated the
sequence of lines you wanted into a single variable in a single
observation.  Of course, my program assumes that no complete
concatenation requires more than 256 bytes.

Regards,
Mark

data test (keep=complete_expression);
  length complete_expression $256;
  infile cards ;
   do until (index(_infile_,'TEST')^=0);
     input;
   end;
   complete_expression=_infile_;
   do while (index(_infile_,'!')=0);
     input;
     complete_expression=catx(' ',complete_expression,_infile_);
   end;
   output;
cards;
This is a TEST.
Can you help!
I want to write SAS code that
scans each line and picks out the word TEST!
The program should search each line for
the word TEST and then concatenates the
following lines until it reaches
the exclamation symbol!
;
run;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google