BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VX_Xc
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

View solution in original post

2 REPLIES 2
Linlin
Lapis Lazuli | Level 10

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

Haikuo
Onyx | Level 15

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 2 replies
  • 855 views
  • 3 likes
  • 3 in conversation