DATA Step, Macro, Functions and more

Number Extraction from Character Column in SAS EG

Accepted Solution Solved
Reply
Contributor
Posts: 55
Accepted Solution

Number Extraction from Character Column in SAS EG

 

Hi , wherever the Number(lessthen five count),Characters and Special Character are availabel then that should be return as "0" and only numbers count greaterthen or equal to 5 then that should return as "1 in sas EG.Kindly help.

 

haveLengthwant
12345661
123456771
1234567881
12345678991
110ask-70
_wertn60
gst30
12330
152640
1235651

 

Thanks,

Siva


Accepted Solutions
Solution
‎03-27-2017 06:43 AM
Regular Contributor
Posts: 194

Re: Number Extraction from Character Column in SAS EG

Hello,

 

data have;
	input x $9.;
	drop toNum;

	toNum=input(x, ? 9.);

	if toNum>9999 and strip(put(toNum,9.))=strip(x) then y=1;
	else y=0;

	cards;
123456
1234567
12345678
123456789
110ask-
_wertn
gst
123
1526
12356
;
run;

View solution in original post


All Replies
Solution
‎03-27-2017 06:43 AM
Regular Contributor
Posts: 194

Re: Number Extraction from Character Column in SAS EG

Hello,

 

data have;
	input x $9.;
	drop toNum;

	toNum=input(x, ? 9.);

	if toNum>9999 and strip(put(toNum,9.))=strip(x) then y=1;
	else y=0;

	cards;
123456
1234567
12345678
123456789
110ask-
_wertn
gst
123
1526
12356
;
run;
Contributor
Posts: 55

Re: Number Extraction from Character Column in SAS EG

Thank you Gamotte
Super User
Posts: 6,948

Re: Number Extraction from Character Column in SAS EG

if notdigit(substr(have,1,length(have))) ne 0 or length(have) < 5
then want = 0;
else want = 1;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 55

Re: Number Extraction from Character Column in SAS EG

Thanks Sir.
Super User
Posts: 9,682

Re: Number Extraction from Character Column in SAS EG


data have;
	input x $9.;
length=length(x);
if length ge 5 and notdigit(strip(x))=0 then flag=1;
 else flag=0;
	cards;
123456
1234567
12345678
123456789
110ask-
_wertn
gst
123
1526
12356
;
run;


Contributor
Posts: 55

Re: Number Extraction from Character Column in SAS EG

Thanks Ksharp
☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 184 views
  • 3 likes
  • 4 in conversation