How do I extract leading non zero digits?
For example for .000212 I want to extract leading digit which is 2. and for 123.933 I want to extract leading digit which is 1.
How do I do this? plz help
How about:
data have;
input nn;
cards;
.00212
123.933
;
data want;
set have;
m=substr(compress(nn,'123456789','k'),1,1);
proc print;
run;
Obs nn m
1 0.002 2
2 123.933 1
Linlin
How about:
data have;
input nn;
cards;
.00212
123.933
;
data want;
set have;
m=substr(compress(nn,'123456789','k'),1,1);
proc print;
run;
Obs nn m
1 0.002 2
2 123.933 1
Linlin
Base on LinLin's method, another function choice would be first(), to save some typing:
data want;
set have;
m=first(compress(nn,'123456789','k'));
run;
Haikuo
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.