View previous topic :: View next topic
|
Author |
Message |
rajesh1183
New User
Joined: 07 Jan 2008 Posts: 98 Location: Hyderabad
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
try a first time switch for "AAA" |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
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
hope it helps |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
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 |
|
|
|