There are a number of ways to specify how to read data into SAS. Rather than me trying to re-write the documentation, take a look at: https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm
However, quick answer to your questions: using something like @"code" code
searches your datafile for the string "code", then inputs whatever is there. However, it will ignore blanks.
If the codes are always in the same position, as in your example, then the following should work:
filename FT15F001 temp;
data have;
infile FT15F001 truncover end=eof;
retain Loc state city postcode code interest second_interest;
informat Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
format Loc $3. state $10. city $12. postcode $5. code $2. interest $35. second_interest $35.;
input @;
if index(_infile_, 'code:') gt 0 then do;
input code 16-17 @"interest: " interest &;
end;
else if index(_infile_, '2nd interest:') gt 0 then do;
input @"2nd interest: " second_interest &;
end;
else do;
if _n_ gt 1 and not missing(loc) then output;
call missing(of _all_);
input Loc state city postcode;
end;
if eof then output;
parmcards;
100 Pahang raub 27600
code: 1A interest: Pine Tree Trail (Bukit Fraser)
2nd interest: Allan's Water (Bukit Fraser)
300 Telangor Klang 41000
code: interest: Something else
500 Selangor Klang 41000
code: 2A interest: Taman Rakyat Klang
400 Selangor Subang Jaya 40150
;
run;
Art, CEO, AnalystFinder.com
... View more