BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
asherer
Obsidian | Level 7

I am trying to convert an excel formula into sas and currently struggling.  The excel formula is

=IF(H11<0,IF(NORMSDIST(H11)<0.0001,"<.0001",NORMSDIST(H11)),IF(1-NORMSDIST(H11)<0.0001,"<.0001",1-NORMSDIST(H11)))


 I am trying to convert this to SAS and H11 equals a field called TSTAT.. I believe I am to use PROBNORM but cant figure out the if part.

if(T1.TSTAT <0,if (PROBNORM(T1.TSTAT) <0.0001,"<.0001",PROBNORM(T1.TSTAT)),if (1-PROBNORM(T1.TSTAT)<0.0001,"<.0001",1-PROBNORM(T1.TSTAT)))
1 ACCEPTED SOLUTION

Accepted Solutions
asherer
Obsidian | Level 7

So My excel code reads

=IF(H11<0,
IF(NORMSDIST(H11)<0.0001,"<.0001",NORMSDIST(H11)),
IF(1-NORMSDIST(H11)<0.0001,"<.0001",1-NORMSDIST(H11)))

I would want to replace the  IF to

IFC(T1.TSTAT<0,
IFC(PROBNORM(T1.TSTAT)<0.0001, then ‘<.0001’ PROBNORM(T1.TSTAT)),
IFC(1-PROBNORM(T1.TSTAT)<0.0001,"<.0001",1-PROBNORM(T1.TSTAT)))

Or how would I go about changing it to more of a series of ifs and then?

View solution in original post

4 REPLIES 4
Reeza
Super User
Can you unchain those IFs to make it more legible? A series of IF/THEN statements would be significantly easier to manage. SAS doesn't have IF as you're attempting to use there. It does have IFN/IFC.
asherer
Obsidian | Level 7

So My excel code reads

=IF(H11<0,
IF(NORMSDIST(H11)<0.0001,"<.0001",NORMSDIST(H11)),
IF(1-NORMSDIST(H11)<0.0001,"<.0001",1-NORMSDIST(H11)))

I would want to replace the  IF to

IFC(T1.TSTAT<0,
IFC(PROBNORM(T1.TSTAT)<0.0001, then ‘<.0001’ PROBNORM(T1.TSTAT)),
IFC(1-PROBNORM(T1.TSTAT)<0.0001,"<.0001",1-PROBNORM(T1.TSTAT)))

Or how would I go about changing it to more of a series of ifs and then?

Reeza
Super User
Pretty sure that code isn't correct, and I would recommend checking it thoroughly. There definitely shouldn't be any 'THEN' in it.
asherer
Obsidian | Level 7

I did not mean to put it was the correct answer  the code I put was not correct. I will attempt to use what you had posted.. Thank you again for your help.

 

p_value = probnorm(tstat);

if p_value < 0 then Display = "<0.0000";
else if p_value  < 0.0001 then Display = "<0.0001";
else if p_value < 0.001 then Display = "<0.001";
else Display = "CHECKME";
Assuming you're using a data step, the following is likely what you want. There's also a format approach that can be handy:
 
SAS also has a defined PVALUE format:, anything less than 0.0001 is coded as <0.0001 and other values show up as their calculated values. 
 
data demo;
do pvalue = 0 to 0.1 by 0.0005;
output;
end;
format pvalue pvalue12.4;
run;
@asherer wrote:
So My excel code reads
=IF(H11<0,
IF(NORMSDIST(H11)<0.0001,"<.0001",NORMSDIST(H11)),
IF(1-NORMSDIST(H11)<0.0001,"<.0001",1-NORMSDIST(H11)))

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1556 views
  • 0 likes
  • 2 in conversation