BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
pavank
Quartz | Level 8
data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;

Qsn: How to extract last number without regex method 

 output

marks

   90

1 00

30

 

1 ACCEPTED SOLUTION

Accepted Solutions
Mazi
Pyrite | Level 9
data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;


data test;
	set ex;
	do i=1 to countw(comments, '');
		word = scan(comments, i, ' ', 'b');
		if ^notdigit(strip(word)) then do;
			put word=;
			leave;
		end;
	end;
run;

Hi, Can you try this?

View solution in original post

5 REPLIES 5
Mazi
Pyrite | Level 9
data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;


data test;
	set ex;
	do i=1 to countw(comments, '');
		word = scan(comments, i, ' ', 'b');
		if ^notdigit(strip(word)) then do;
			put word=;
			leave;
		end;
	end;
run;

Hi, Can you try this?

Ksharp
Super User
data ex;
input comments:& $200.;
want=scan(comments,-1,,'kd');
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;
pavank
Quartz | Level 8

Hi @Ksharp  

Thank you very much for your solution

Astounding
PROC Star
For these lines of data, what should the last number be?
A89 90
4 a1b2c
pavank
Quartz | Level 8

Hi @Astounding ,

As per your question

data ds;
input text :& $ 200.;
want=scan(text,-1,,'kd');
cards;
A89 90
4 a1b2c
a44bcc3
22bsi44-5c
9tt$b21t88
;
proc print;
run;

i can use Scan function with 'kd'  modifier

PFabove

 

pavank_0-1719809436620.png

 

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!

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
  • 5 replies
  • 888 views
  • 3 likes
  • 4 in conversation