DATA Step, Macro, Functions and more

Conditional formatting

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Conditional formatting

[ Edited ]

Hi,

 

Could someone in the forum help me to work on the following issue:

 

My dataset has 8 columns in the following structure:

Method1 -- Method4 Var1-Var4

 

All variables are numeric.

 

I have to output frequencies in % for each variable Method1-Method4 using their 3 level formats (Above range, Below range, within range) and Va1-Var4 using their 3 level formats (Positive significant, Negative significant and insignificant).

 

For Method1--Method4, it is easily to define as 3-level class variables using Proc format. However, Var1-Var4 is defined conditionally on the value of Method1-Method4 such as:

 

1. Var1-Var4 is defined as insignificant if they are >=0.05

2. Var1<0.05 and Method1 is positive number, Var1 will be defined as positive significant

3. If var1<0.05 and Method1 is negative number, Var1 will be redefined as negative significant.

 

Similar formats apply to the remaining Var2-Var4.

 

Is there any nice way to format Var1-Var4 using Proc format. As I have 4 pairs of variable (Var1 v Method1, Var2 v Method2,...), using if .. then .. else looks repeating.

 

Thanks, Mai

 

 

 

 

 

 

 


Accepted Solutions
Solution
‎06-28-2016 10:04 PM
Super User
Posts: 17,840

Re: Conditional formatting

[ Edited ]

Hopefully this gives you the idea:

 

data want;
set have;
length cat1-cat4 $25.;
array pvalues(4) method1-method4;
array effect(4) var1-var4;
array category(4) $ cat1-cat4;

do i=1 to 4;
    if pvalues(i)<0.05 and effect(i)<0 then category(i)='Negative Significant';
    else if pvalues(i)>=0.05 ... then category(i)='Positive Significant';
    else .... ;
end;
run;  

View solution in original post


All Replies
Super User
Posts: 17,840

Re: Conditional formatting

I *think* you're stuck with creating 8 new variables. I'm slightly confused because you say you have 8 variables but then indicate var2-var7?

 

You can reduce the number of IF/THEN by using arrays so you only have one set of code to implement the rule. 

 

If you clarify your variables and the relationship, someone can help in the code.


q5pham wrote:

 

 

My dataset has 8 columns in the following structure:

Method1 -- Method4 Var1-Var4

 

 

 

1. Var1-Var4 is defined as insignificant if they are >=0.05

2. Var1<0.05 and Method1 is positive number, Var1 will be defined as positive significant

3. If var1<0.05 and Method1 is negative number, Var1 will be redefined as negative significant.

 

Similar formats apply to the remaining Var2-Var7.

 

Is there any nice way to format Var1-Var7 using Proc format. As I have 4 pairs of variable (Var1 v Method1, Var2 v Method2,...), using if .. then .. else looks repeating.

 

Thanks, Mai

 

 

 

Contributor
Posts: 24

Re: Conditional formatting

Thanks Reeza for spotting out my typo mistakes. I have corrected, meaning i have 4 variables Method1-Method4 and 4 variable Var1-Var4 only.

 

 

Solution
‎06-28-2016 10:04 PM
Super User
Posts: 17,840

Re: Conditional formatting

[ Edited ]

Hopefully this gives you the idea:

 

data want;
set have;
length cat1-cat4 $25.;
array pvalues(4) method1-method4;
array effect(4) var1-var4;
array category(4) $ cat1-cat4;

do i=1 to 4;
    if pvalues(i)<0.05 and effect(i)<0 then category(i)='Negative Significant';
    else if pvalues(i)>=0.05 ... then category(i)='Positive Significant';
    else .... ;
end;
run;  
Contributor
Posts: 24

Re: Conditional formatting

Thank you very much Reeza.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 242 views
  • 0 likes
  • 2 in conversation