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

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

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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

 

 

 

q5pham
Obsidian | Level 7

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

 

 

Reeza
Super User

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;  
q5pham
Obsidian | Level 7

Thank you very much Reeza.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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