Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Data step sort vars by # decimal places

Data step sort vars by # decimal places

Data step sort vars by # decimal places

Hello, I am working with numeric variables that are in one of the following three formats XX.XX, XX.X, and XX.  I am trying to match the variables to clinical codes that do not have decimal places.

My first thought was to multiply by 100, but this introduces zeros for the XX.X and XX formats (which is to say, XXX0 and XX00).  The clinical codes corresponding to these vars are in the following format XXX and XX.  

How can I identify and group the different formats in the data statement to manipulate them individually?  Or:  XX.XX*100, XX.X*10 and XX left alone?

Any suggestions would be greatly appreciated.

RE: Data step sort vars by # decimal places

You can turn the number via format to a string w/o trailing zeros and remove punctuation with compress. Below example assumes you have max width of 5 characters incl a potential dot.

data x;
  val = 23.45; output;
  val = 23.4; output;
  val = 23.; output;

data _null_;
  set x;
  length valTxt $5;
  valTxt = compress (put (val, best5.), '', 'p');
  put val= valTxt=;

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close