BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eric2
Calcite | Level 5
Hi,
How do we calculate significant digits based on the value?
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
;
Looking for something like this.

101 aaaa 1 97.23 4
101 aaaa 2 99.3 3
101 aaaa 3 100.003 6
102 aaaa 1 69.3 3
102 aaaa 2 0.0006 1
102 aaaa 3 0.36570 5
Thanks,
E
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

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;
eric2
Calcite | Level 5
I think 0.36570 will have 5 , as 3 6 5 7 0 correct?
eric2
Calcite | Level 5
Thanks. I think this is what I was looking. Thanks kurt
ballardw
Super User

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
;
Tom
Super User Tom
Super User

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
Calcite | Level 5
0.0006 I believe should have 1 significant digit which is 6.
Tom
Super User Tom
Super User

@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.  

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!

How to Concatenate Values

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.

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
  • 8 replies
  • 1136 views
  • 0 likes
  • 4 in conversation