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

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 336 views
  • 3 likes
  • 4 in conversation