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
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;
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
Thanks Reeza for spotting out my typo mistakes. I have corrected, meaning i have 4 variables Method1-Method4 and 4 variable Var1-Var4 only.
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;
Thank you very much Reeza.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: