IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SAS : Create single observation from multiple observations


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajesh1183

New User


Joined: 07 Jan 2008
Posts: 98
Location: Hyderabad

PostPosted: Wed Nov 03, 2010 10:00 pm
Reply with quote

Hi,

I have a input data of LRECL=150 as below
Code:

AAA

1111111111111111111111111111111
2222222222222
333333333333333333333333333333333333


AAA

4444
5555555555555


AAA

7777777777777
888
9999999999999999999
00000000000000000


When ever the string 'AAA' was encountered, it was treated as seperate profile.
And I need output as below
Code:

AAA

1111111111111111111111111111111#2222222222222#333333333333333333333333333333333333


AAA

4444#5555555555555

AAA

7777777777777#888#9999999999999999999#00000000000000000



I was reading the input file until I encounter 'AAA'
and then executing the below code

Code:

length str_data $5000.;
do until (SUBSTR(DATA_1,1,3) = 'AAA');
   INFILE IPFILE;                             
   INPUT @001 DATA_1  $char150.               
  ;                                           
  str_data=str_data||data_1||'#z ';           
end;               
FILE OPFILE
PUT @001 str_data;
run;

 


I was receiving LOST CARD error..?? any clue..?
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 03, 2010 10:18 pm
Reply with quote

try a first time switch for "AAA"
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Nov 03, 2010 10:45 pm
Reply with quote

LOST CARD means either you're using a line pointer such as the / in your INPUT statement, or you have multiple INPUT statements in your DATA step -- and something's not in sync.

And I hope you do realize that
Quote:
str_data=str_data||data_1||'#z ';
won't quite do what you think -- SAS uses the full variable length when concatenating, so it'll attempt to append your 150 byte input line to the end of the 5000 bytes of spaces -- which it does -- and then truncates back down to 5000 bytes, so your appended data gets removed. Hint: the TRIM function comes in handy.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Nov 08, 2010 12:40 pm
Reply with quote

For the last record i.e. after reading the 3rd AAA, since there is a DO UNTIL, it continuosly executes INPUT statement indefinitely. it can't find a corresponding record. So you are getting the LOST RECORD.

Also I hope you would have noted that you missed out a ';' on
Code:
FILE OPFILE


hope it helps
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Nov 08, 2010 2:43 pm
Reply with quote

The below program produces the required o/p:

Code:
data blackdog;                                                       
infile 'FILE.NAME' end=last;                                     
File 'outfile';
retain data_1 str_data;                                               
retain first_flag 1;                 *for first 'AAA' occurence alone;
length str_data $5000 data_1 $150;                                   
input testflag $ 1-3 @;                                               
if testflag = 'AAA' or testflag = '   ' then do;                     
   put testflag;                                                     
   if first_flag = 0 then do;                                         
       put str_data;                                                 
       str_data = '';                                                 
   end;                                                               
   else do;                                                           
       first_flag = 0;                                               
   end;                                                               
end;                                                                 
else do;                                                             
     input @1 data_1 $;                                               
     if str_data = '' then str_data = trim(data_1) ;                 
     else str_data = trim(str_data) || '#' || trim(data_1);           
end;                                                                 
if last then put str_data;                                           
run;                                 


I/P:

Code:
AAA                                 
                                   
1111111111111111111111111111111     
2222222222222                       
333333333333333333333333333333333333
                                   
                                   
AAA                                 
                                   
4444                               
5555555555555                       
                                   
                                   
AAA                                 
                                   
7777777777777                       
888                                 
9999999999999999999                 
00000000000000000               


O/P:

Code:
AAA                                                                     
                                                                       
                                                                       
                                                                       
1111111111111111111111111111111#2222222222222#3333333333333333333333333333                                                                     
                                                                       
                                                                       
AAA                                                                     
                                                                       
                                                                       
                                                                       
                                                                       
4444#5555555555555                                                     
                                                                       
                                                                       
AAA                                                                     
                                                                       
                                                                       
                                                                       
7777777777777#888#9999999999999999999#00000000000000000       


Hope it helps.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts How to create a list of SAR jobs with... CA Products 3
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
Search our Forums:

Back to Top