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
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.