BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Caro17
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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,'.');
--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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,'.');
--
Paige Miller
Caro17
Calcite | Level 5

Yes, the structure is always the same. And yes, I need the three characters on the left.

Astounding
PROC Star

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.

 

 

Caro17
Calcite | Level 5

I get the result I want with the version from PaigeMiller.

 

newstring = scan(oldstring,1,'.');

 

Thanks a lot!

ed_sas_member
Meteorite | Level 14

Hi @Caro17 

Please try this, to begin with the character in first position

diag = substr(diagnose,1,3);

Best,

Tom
Super User Tom
Super User

Position numbers start with 1, not zero.  Just like normal counting.

sas-innovate-wordmark-gradient-background 3.pngSAS Innovate

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3817 views
  • 1 like
  • 5 in conversation