The solution would be to read the "fixed" values backwards first and then search for the stat1 value in the input record to determine where the last character of city is.
data want;
length city_name $30 stat1-stat3 8;
input ;
stat3 = input(scan(_infile_,-1),8.);
stat2 = input(scan(_infile_,-2),8.);
stat1 = input(scan(_infile_,-3),8.);
city_name = substr(_infile_,1,find(_infile_,scan(_infile_,-3))-1);
cards;
idaho 123 345 789
los angeles 234 567 890
papua new guniea 765 432 109
;
run;
So your code would look like this:
data stats2;
infile "/folders/myfolders/datasets/sample1.dat" ;
length city_name $30 stat1-stat3 8;
input ;
stat3 = input(scan(_infile_,-1),8.);
stat2 = input(scan(_infile_,-2),8.);
stat1 = input(scan(_infile_,-3),8.);
city_name = substr(_infile_,1,find(_infile_,scan(_infile_,-3))-1);
run;
... View more