Help using Base SAS procedures

How do I extract leading non zero digits?

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

How do I extract leading non zero digits?

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


Accepted Solutions
Solution
‎03-21-2012 12:08 AM
Super Contributor
Posts: 1,636

How do I extract leading non zero digits?

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


All Replies
Solution
‎03-21-2012 12:08 AM
Super Contributor
Posts: 1,636

How do I extract leading non zero digits?

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

Respected Advisor
Posts: 3,124

How do I extract leading non zero digits?

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

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 212 views
  • 3 likes
  • 3 in conversation