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

 

 

I have a quick question on separating numbers and units in SAS.  
 
So the data I'm having is "10 MG-25MG", I want to separate "10" with "MG-25MG".
 
I have tried 
data want;
	txt = "100/50 mg medicin";
	c = compress(txt,"0123456789.,/ ","K"); *K is to keep the chars you specified.;
	txt_b = compress(txt,"0123456789.,/");
run;

 

But my output is "1025", not "10". Can you please help?
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Maybe this will help:

data want;
	txt = "10mg-25mg";
   a = scan(txt, 1, '-');  /* get text before the dash */
   b = scan(txt, 2, '-');  /* get text after the dash */
   a_val = input(compress(a,' ', 'A'), 10.); /* get rid of letters, convert to number */
   b_val = input(compress(b,' ', 'A'), 10.);
run;

proc print;run;
proc contents; run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Your words and your code don't match.

 

You words say that you want to separate 10 from the rest of the text, and yet in your code there is no 10. Could you clarify this, please?

--
Paige Miller
desireatem
Pyrite | Level 9
Sure. Here is my data structure:
Drug Strength
A/B 10 MG-25MG
 
I tried:
data drug;
set drug;
dose=compress(strength,"0123456789.,/ ","K");
unit = compress(strength,"0123456789.,/");
run;
 
Then I get: 
Drug  Dose Unit 
A/B 1025 MG-MG
What I want is :
Drug  Dose Unit 
A/B 10 MG-25MG
Rick_SAS
SAS Super FREQ

Maybe this will help:

data want;
	txt = "10mg-25mg";
   a = scan(txt, 1, '-');  /* get text before the dash */
   b = scan(txt, 2, '-');  /* get text after the dash */
   a_val = input(compress(a,' ', 'A'), 10.); /* get rid of letters, convert to number */
   b_val = input(compress(b,' ', 'A'), 10.);
run;

proc print;run;
proc contents; run;
desireatem
Pyrite | Level 9

Thank you Rick!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 792 views
  • 1 like
  • 3 in conversation