The SAS Output Delivery System and reporting techniques

Delimiter-based pointer control

Reply
Frequent Contributor
Posts: 95

Delimiter-based pointer control

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.
N/A
Posts: 0

Re: Delimiter-based pointer control

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;
Frequent Contributor
Posts: 95

Re: Delimiter-based pointer control

Posted in reply to deleted_user
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).
N/A
Posts: 0

Re: Delimiter-based pointer control

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.
N/A
Posts: 0

Re: Delimiter-based pointer control

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
Ask a Question
Discussion stats
  • 4 replies
  • 124 views
  • 0 likes
  • 2 in conversation