Desktop productivity for business analysts and programmers

Numerical Digits between spaces

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Numerical Digits between spaces

[ Edited ]

Hi Guys . I am only interested in the underlined digits. I have tried with the compress and substr but no luck.


Example of data;

P2Pb 430 041017
P2P 10538 030517 DIBS
P2P 496 01092017
P2P 2594 01112016

thanks in advance.


Accepted Solutions
Solution
a week ago
Super User
Super User
Posts: 8,181

Re: Numerical Digits between spaces

[ Edited ]
data want;
  set have;
  want=input(scan(thedata,2," "),best.);
run;

Note I assume your data is called have and the variable is thedata.

Post test data in the form of a datastep in the post using a code window, we cannot guess!!!! 

View solution in original post


All Replies
Regular Contributor
Posts: 161

Re: Numerical Digits between spaces

Please post the code you tried, so that it is easier to suggest corrections. You can use the scan-function to get the second part of the string, then use the input-function to convert the extract to a number.

Solution
a week ago
Super User
Super User
Posts: 8,181

Re: Numerical Digits between spaces

[ Edited ]
data want;
  set have;
  want=input(scan(thedata,2," "),best.);
run;

Note I assume your data is called have and the variable is thedata.

Post test data in the form of a datastep in the post using a code window, we cannot guess!!!! 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 120 views
  • 0 likes
  • 3 in conversation