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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.