Hi,
Could anyone help me with this issue please? The column is currently is like this:
| 30012324431440~~PABC |
I want to extract the 30012324431440 (number part) and PABC(character part) into two different column. And the separation part is ~~.
Thank you
Hope this helps
data split;
set test;
length var1-var2 $15.;
array var(2) $;
do i = 1 to dim(var);
var[i]=scan(row,i,'~~');
end;
run;
Hope this helps
data split;
set test;
length var1-var2 $15.;
array var(2) $;
do i = 1 to dim(var);
var[i]=scan(row,i,'~~');
end;
run;
One way:
data example; str="30012324431440~~PABC"; numpart = scan(str,1,'~'); Charpart = scan(str,2,'~'); run;
The Scan function will treat multiple adjacent delimiters, such as the ~, as a single "word" value.
If you want to have an actual numeric value for the numeral part you could add
numeric = input(numpart,15.);
but if you have more than 15 digits you will likely run into numeric precision storage issues.
data work.one;
numchar='30012324431440~~PABC';
format num best15.;
num=input(substr(numchar,1,14),14.);
char=substr(numchar,17,4);
run;
if you don't format num as best15, it will appear using scientific notation.
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 save with the early bird rate—just $795!
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.