SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Stalk
Pyrite | Level 9

I would like to extract just the number 27.59 from the following Positive (27.59). Irrespective of the text before the parenthesis.

 

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

SCAN() will work well as long as the text before (or after if searching backwards) does not include parentheses.

number = input(scan(string,1,'()'),32.);

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

SCAN() will work well as long as the text before (or after if searching backwards) does not include parentheses.

number = input(scan(string,1,'()'),32.);
jimbarbour
Meteorite | Level 14

It sounds like you know the number that you are searching for in advance; is that correct?  If so, see the code below.  I'm using a combination of the FIND, LENGTH, and SUBSTR functions.  I'm sure there are other ways to do it as well.

 

Regards,

 

Jim

 

Results:

jimbarbour_0-1622057293236.png

Code:

DATA	_NULL_;
	Search_For	=	'27.59';
	Search_Len	=	LENGTHN(Search_For);
	Var			=	'Positive (27.59)';

	Number	=	SUBSTR(Var, FIND(Var,'27.59'), Search_Len);

	PUTLOG	"NOTE:  "  Number=;
	PUTLOG	"NOTE-  "  ;
RUN;
Stalk
Pyrite | Level 9

Thank you Tom and Jim for the quick response. 

 

I used the following..ct_value= scan(Result,2,'()');

I just need the number with in parenthesis for all the records. 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3 replies
  • 1071 views
  • 1 like
  • 3 in conversation