Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SAS : Create single observation from multiple observations

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: SAS : Create single observation from multiple observations
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: 2436
Location: Netherlands, Amstelveen

PostPosted: Wed Nov 03, 2010 10:18 pm    Post subject:
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: 8131
Location: East Dubuque, Illinois, USA

PostPosted: Wed Nov 03, 2010 10:45 pm    Post subject:
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: 1510
Location: Chennai

PostPosted: Mon Nov 08, 2010 12:40 pm    Post subject:
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: 1510
Location: Chennai

PostPosted: Mon Nov 08, 2010 2:43 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Multiple VSAM files single output fil... Mohan Kothakota DFSORT/ICETOOL 11 Wed Aug 09, 2017 7:57 pm
This topic is locked: you cannot edit posts or make replies. rexx to create a tso command Bharath Vikraman CLIST & REXX 1 Tue Aug 08, 2017 3:32 pm
This topic is locked: you cannot edit posts or make replies. rexx code to create a ps file Bharath Vikraman CLIST & REXX 4 Mon Aug 07, 2017 10:30 am
No new posts How do you create Eclipse based dialogs jasorn IBM Tools 0 Thu Aug 03, 2017 5:05 pm
No new posts Read two inputs and write into output... murali.andaluri DFSORT/ICETOOL 6 Wed Jul 26, 2017 7:35 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us