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
;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.