BookmarkSubscribeRSS Feed
1162
Calcite | Level 5
I have a tab delimited file with 116 variables in it. I only need the 13th and 71st variables for the project I'm doing.

Is there some way to skip 12 tabs and then read in a variable? I came up with this solution, but I'm hoping there is a better one.

data work.in;
infile "delimited.txt" dlm='09'X dsd missover;
input @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X @'09'X Identifier :$16.;
run;

I would have to put in 57 more @'09'Xs to read in my next variable. I don't want to use dummy variables that I later drop because the columns are a mix of character and numeric formats of varying lengths.

Thanks.
4 REPLIES 4
deleted_user
Not applicable
just thinking out loud, but you might try a do loop?

*this is pseudo code;
array var(116);
do i = 1 to 116;
input var(i) @;
if i in (13, 71);
end;
1162
Calcite | Level 5
Thanks. Your idea worked well for me after tweaking it a bit. Here's what I ended up with:

data work.a (drop=i cell);
infile "delimited.txt" dlm='09'X dsd missover lrecl=2048;
do i = 1 to 71;
input cell :$16. @;
if i = 13 then Identifier = cell;
if i = 71 then Value = input(cell, 8.);
end;
output;
run;

Still, I thought there was a way to move the pointer by a number of delimiters so that this could all be written as one input statement (no loops or if-then steps).
deleted_user
Not applicable
glad to see it worked out for you!

i think the only way to selectively read variables is if the file is fixed-width? otherwise, you need to read everything on the line up to the last variable you want to keep.
deleted_user
Not applicable
that approach uses a loop in the data step iteration over which you can improve, just a little.
The "input" statement allows some economy of syntax/processing by using variable lists, like in this example :[pre]
data reduced( keep= identifier value ) ;
length dum1-dum70 $1 ;
informat identifier $16. value 8.;
infile "delimited.txt" dsd dlm= '09'x truncover lrecl= 2048 ;
input dum1-dum12 identifier dum14-dum70 value ;
run;[/pre]

Happy New Year

PeterC

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 4 replies
  • 1497 views
  • 0 likes
  • 2 in conversation