Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- ODS and Base Reporting
- /
- Find smallest value in variable list

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-22-2007 11:44 AM

I wrote code to calculate the proportion of the normal (0,1) distribution less than x from -2.5 and 0. Now I would like to print out the x value that is closest to the probability value = .10. How do I do this? After looking at the output the x value is -1.30 but I want to find this automatically and print. Any suggestions?

data one;

do x = -2.5 to 0 by .05;

probablity = probnorm(x);

difference = abs(.1-probability); *the smallest value of difference and its corresponding x value would be what I want to print out;

output;

end;

proc print data=one;

run;

data one;

do x = -2.5 to 0 by .05;

probablity = probnorm(x);

difference = abs(.1-probability); *the smallest value of difference and its corresponding x value would be what I want to print out;

output;

end;

proc print data=one;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-23-2007 04:08 AM

I corrected the inconsistent spellings of probability, and added some code to the step.

Essentially, you hold a value which is the smallest and compare it to the difference.

If difference is lower than smallest then update smallest.

Otherwise it is larger and has started to increase again. So output the record at that point and stop the data step.

You now have one record with the smallest value and related X value.

If you don't like the column names, issue a rename option on the data statement.

Kind regards

David

Data ONE;

SMALLEST = 9999;

Do X = -2.5 To 0 By .05;

PROBABILITY = ProbNorm( X);

DIFFERENCE = ABS( .1 - PROBABILITY);

* the smallest value of difference and its corresponding

x value would be what I want to print out;

If DIFFERENCE < SMALLEST Then Do;

SMALLEST = DIFFERENCE;

XVALUE = X;

End;

Else Do;

Output;

Stop;

End;

End;

Run;

Essentially, you hold a value which is the smallest and compare it to the difference.

If difference is lower than smallest then update smallest.

Otherwise it is larger and has started to increase again. So output the record at that point and stop the data step.

You now have one record with the smallest value and related X value.

If you don't like the column names, issue a rename option on the data statement.

Kind regards

David

Data ONE;

SMALLEST = 9999;

Do X = -2.5 To 0 By .05;

PROBABILITY = ProbNorm( X);

DIFFERENCE = ABS( .1 - PROBABILITY);

* the smallest value of difference and its corresponding

x value would be what I want to print out;

If DIFFERENCE < SMALLEST Then Do;

SMALLEST = DIFFERENCE;

XVALUE = X;

End;

Else Do;

Output;

Stop;

End;

End;

Run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-24-2007 11:16 AM

Thanks David, I really appreciate it.