hi,
i have 12.2.3.4
12.33.44.55
122.333.333.55
variable having data like above would like to extract first 3 parts. by using substring it is not possible is there any other functions in sas to get result like below
12.2.3
12.33.44
122.333.333
data have;
infile datalines truncover;
input string $20.;
datalines;
12.2.3.4
12.33.44.55
122.333.333.55
12.2
;
data want;
set have;
if 0 then string_want=string;
string_want=catx('.',scan(string,1,'.'),scan(string,2,'.'),scan(string,3,'.'));
run;
proc print data=want;
run;
Hi @vallsas,
@vallsas wrote:
... would like to extract first 3 parts. by using substring it is not possible ...
Why not?
data want;
input have :$30.;
want=substr(have,1,findc(have,'.','b')-1);
cards;
12.2.3.4
12.33.44.55
122.333.333.55
;
Or, if the number of "parts" varies:
data want(drop=pos len);
input have :$30.;
call scan(have,3,pos,len);
want=substr(have,1,pos+len-1);
cards;
12.2.3.4.5
12.33.44.55.66.77
122.333.333.55.6.77.888.9
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.