BookmarkSubscribeRSS Feed
Patrick
Opal | Level 21
Hi All
For a case like in the example below:
Is there an efficient and elegant way to tell the input statement that I only want to read the field after the second delimiter?
Is there a way how I can avoid having to map and then drop columns a and b?

data _null_;
infile datalines dsd dlm='|' truncover;
input a $ b $ c $;
put c=;
drop a b;
datalines;
aaaa|bbb|ccc||ee
u|ww||yy|z
1|222|3333333|4|5
;

Thanks, Patrick
5 REPLIES 5
DanielSantos
Barite | Level 11
Hi, if you just need C, you could parse directly from the input buffer, like this.

data _null_;
infile datalines dsd /* dlm='|' */ truncover;
input /* a $ b $ c $ */;
C=scan(_infile_,3,'|');
put c=;
/* drop a b; */
datalines;
aaaa|bbb|ccc||ee
u|ww||yy|z
1|222|3333333|4|5
;

be sure to prealocate a large enough length for the C var.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
data_null__
Jade | Level 19
[pre]
19 data _null_;
520 infile datalines dsd dlm='|' truncover;
521 input @'|' @'|' c:$8.;
522 put c=;
523 list;
524 datalines;

c=ccc
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
525 aaaa|bbb|ccc||ee
c=
526 u|ww||yy|z
c=3333333
527 1|222|3333333|4|5
[/pre]
Patrick
Opal | Level 21
Thank you guys!

Didn't think about the approach data _null_ took. Too bad that there is no such thing as a "repeater" (i.e. 5*@'|').

Thanks, Patrick
DanielSantos
Barite | Level 11
Oh... but you code easily code that:

%macro repeat(N);
%do I=1 %to &N;
@ '|'
%end;
%mend repeat;

options mprint;

data _null_;
infile datalines dsd dlm='|' truncover;
input %repeat(2) c:$8.;
put c=;
list;
datalines;
aaaa|bbb|ccc||ee
u|ww||yy|z
1|222|3333333|4|5
run;
Peter_C
Rhodochrosite | Level 12
just use a KEEP.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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