Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SKIP input fields in a comma delimited file

Status
Not open for further replies.

ThompsonA

Technical User
Jan 30, 2002
10
US
I am reading in a raw data file that is delimited by commas and quotes around text fields. My data looks like:

"Smith",30,90,100,120,130,140,150,160,"Philadelphia"

Most of the fields in the raw data file are not needed and I would like to SKIP the unused fields when creating my INPUT statement.

Is there a way that I can avoid defining all the fields that are of no interest?

In the example above, my INPUT statement could look like:

INPUT Name
Age
Value1
Value2
Score1
Score2
Result1
Result2
City ;

However, in my actual data there are over 70 fields that I would have to define. Is there someway that I can specify only the two or three variables that I need and skip all the others.

Any advise will be appreciated. Thank you!
 
Try this:

data tst(drop = temp);
infile datalines dsd;
input f1 $ temp temp temp f2 $;
datalines;
row1f1, 1, 2, 3, row1f2
row2f1, 1, 2, 3, row2f2
row3f1, 1, 2, 3, row3f2
row4f1, 1, 2, 3, row4f2
;
run;

If there are too many fields you don't want, use macro.

%macro read(var, start_n, end_n, f);
%do i = &start_n %to &end_n;
&var &f
%end;
%mend read;

data tst(drop = temp tempc);
infile datalines dsd;
input f1 $ %read(temp, 2, 4) %read(tempc, 5,5,$);
datalines;
row1f1, 1, 2, 3, row1f2
row2f1, 1, 2, 3, row2f2
row3f1, 1, 2, 3, row3f2
row4f1, 1, 2, 3, row4f2
;
run;
In this example, only first field remains.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top