Hey,
my boss wants to know how often he diagnosed a certain disease. That means I have alphanumeric values, e. g. "A12.9". Now I want to cut this value, so that I get in a different column "A12". I have tried several things but it didn't function.
For example I used a data-set with "diag = substr(diagnose,0,3);" however the column keeps empty. I tried also "substr(m.strdiagnose,0,3) as dia" within the select-statement in proc sql and the column keeps empty as well.
What else can I try to solve this problem? Thanx a lot for your help.
I am using SAS Enterprise Guide Version 7.15 HF2.
Caro
Its hard to generalize from a single example. Is there always a period in the character string? Do you always want the text to the left of the period?
Try
newstring = scan(oldstring,1,'.');
Its hard to generalize from a single example. Is there always a period in the character string? Do you always want the text to the left of the period?
Try
newstring = scan(oldstring,1,'.');
Yes, the structure is always the same. And yes, I need the three characters on the left.
Given that you always want the first three characters, here is a simple way:
data want;
length newstring $ 3;
set have;
newstring = oldstring;
run;
There's only room to store 3 characters in NEWSTRING, so you will end up with the first three.
I get the result I want with the version from PaigeMiller.
newstring = scan(oldstring,1,'.');
Thanks a lot!
Hi @Caro17
Please try this, to begin with the character in first position
diag = substr(diagnose,1,3);
Best,
Position numbers start with 1, not zero. Just like normal counting.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.