Here my code suggestion:
data a;
input subject $ MITESTCD $ VISITNUM MIORRES;
datalines;
101 aaaa 1 97.23
101 aaaa 2 99.3
101 aaaa 3 100.003
102 aaaa 1 69.3
102 aaaa 2 0.0006
102 aaaa 3 0.36570
;
data want;
set a;
string = compress(put(miorres,best32.)," .");
do while (substr(string,1,1) = "0");
string = substr(string,2);
end;
sig = length(string);
drop string;
run;
If the result for obs 5 has to be 1, then the result for obs 6 must be 4.
Here my code suggestion:
data a;
input subject $ MITESTCD $ VISITNUM MIORRES;
datalines;
101 aaaa 1 97.23
101 aaaa 2 99.3
101 aaaa 3 100.003
102 aaaa 1 69.3
102 aaaa 2 0.0006
102 aaaa 3 0.36570
;
data want;
set a;
string = compress(put(miorres,best32.)," .");
do while (substr(string,1,1) = "0");
string = substr(string,2);
end;
sig = length(string);
drop string;
run;
Significant digits are usually related to how the data is collected and rules for projects. Typically all values for the same variable should be considered as having the name number of significant digits based on those rules.
I am very concerned about the treatment of 0.0006 as one significant digit for a variable that also has 0.36570 treated as five. The 3 zeroes between the decimal an the 6 in the first are generally considered "signficant" if the 6 is.
If your "value" is not read as character there really is not going to be any way to detect the trailing 0 in 0.36570 either.
So you may need to explain the actual rules for determining "significance".
BTW, as posted your data step does not run properly for two reasons. First your Mitestcd variable has character values and is not indicated as such on the input statement.
Second, this forum reformats pasted text removing most white space. So the columns were shifted. When pasting code, log entries or anything that may be column sensitive you need to open a text box on the forum using the </> icon and paste there. Example:
data a; input @1 subject $3. @5 MITESTCD $ @15 VISITNUM @25 MIORRES ; datalines; 101 aaaa 1 97.23 101 aaaa 2 99.3 101 aaaa 3 100.003 102 aaaa 1 69.3 102 aaaa 2 0.0006 102 aaaa 3 0.36570 ;
If you have already converted the string into a number then you cannot detect that last zero in the last observation as a significant digit.
Similarly how many significant digits are in a string like '0.0006'?
@eric2 wrote:
0.0006 I believe should have 1 significant digit which is 6.
That is not what SIGNFICANT digits means. Significant digits is based on what was actually measured. Just looking a that number there is no way to know whether only the last digit is what was measured. It could be that three significant digits were measure and the first two just happened to be zeros.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.