BookmarkSubscribeRSS Feed
Caz
Calcite | Level 5 Caz
Calcite | Level 5

Hi,

I have a file that reads more like a report and need to create some BASE SAS to pick up the fields we are interested in. I have created a dummy example of the type of format that I have with 1 example but then it repeats in this format with the Text, then the next record. (see below)

I would like to be able to get a file with 1 row per record that in that one row, shows the fields

Recordstart

Jo Blogs, 1 High St, London

Pat Post, Flat 123, The Shard, London

199999.99 EUR

EUR 10.00

ABC Processing Centre, Whitechapel, London

Dummy Example of Format of file
Lots of Text, Lots of Text, Lots of Text.........................

Lots of Text, Lots of Text, Lots of Text for a few rows....

Format = Recordsart

Identifier = 123.ext.out

Customer1 =

               Jo Blogs

               1 High St

               London

              

Customer2 =

               Pat Post

               Flat 123

               The Shard

               London

Reference = 12345

Amount = 199999.99 EUR

Version = 132                                 Check = Yes

System = FIN                                 Passed = Yes    

Block4:

Field1: EUR 10.00

Field2: ABC Processing Centre

Whitechapel

London

Field3: ABCXXX

Has anyone had experience of such a file and can assist?

Caz    

1 REPLY 1
DBailey
Lapis Lazuli | Level 10

assuming everything is consistent (which might be a big assumption).

data want(keep=rec);

infile fid;

length

     txt $100.

     rec $100.

;

retain rec;

input txt & $100.;

if substr(txt,1,8)='Customer' then do; /*handles customer1 and customer2*/

     rec='';

     input txt & $100.; /*name*/

     rec=compress(txt);

     input txt & $100.; /*address*/

     rec=catx(', ',rec,txt);

     input txt & $100.; /*city*/

     rec=catx(', ',rec,txt);

     output;

     end;

else if substr(txt,1,9)='Amount = ' then do;

     rec=substr(txt,10);

     output;

     end;

else if substr(txt,1,7)='Field1:' then do;

     rec=substr(txt,9);

     output;

     end;

else if substr(txt,1,7)='Field2:' then do;

     rec=substr(txt,9);

     input txt & $100.; /*address*/

     rec=catx(', ',rec, txt);

     input txt & $100.; /*city*/

     rec=catx(', ',rec, txt);

     output;

     end;

run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 749 views
  • 0 likes
  • 2 in conversation