Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data step sort vars by # decimal places

Status
Not open for further replies.

cookaaronl

Programmer
Feb 14, 2011
1
0
0
US
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.
 
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;
run;

data _null_;
set x;
length valTxt $5;
valTxt = compress (put (val, best5.), '', 'p');
put val= valTxt=;
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top