Hello everyone,
I have a sample code as below. My question probably will be found strange to you. You will try to understand the logic the behind of the code. I have to say that the code goes through a process then coming into this shape such as Have1, Have2,Have3 and Have4 data set. If it becomes like Have1, everything is okay, the code works as I want. However, if it becomes like Have2,Have3 or Have4 the result does not seem as I want.
At this point, I want to change this structure from static to dynamic. I thought, if I use macro-mend, maybe I can reach my aim. "Set" suffix values can change, I just want to build structure which is proper with Proc Report match-ups, if the data set doesn't have Set1,Set2,Set3 and Set4 suffixes, then no extra columns will come.
Here is my code;
Data Have1;
Length VariableName $ 50 DataSetSuffix $ 50 Values 8;
Infile Cards;
Input VariableName DataSetSuffix Values;
Cards;
Variable1 Set1 0.2
Variable2 Set1 0.4
Variable3 Set1 0.6
Variable1 Set2 0.3
Variable2 Set2 0.5
Variable3 Set2 0.7
Variable1 Set3 0.4
Variable2 Set3 0.6
Variable3 Set3 0.8
Variable1 Set4 0.5
Variable2 Set4 0.7
Variable3 Set4 1.0
;
Run;
PROC Report Data=Have1 Nowd SpanRows
Style(Summary) = Header {FontWeight=Bold Color=#112277}
Style(Header)=Header [BorderColor=Black BorderWidth=1px VerticalAlign=M]
Style(Column)=[BorderColor=Black BorderWidth=1px] Out=Want;
Column ("Variable" VariableName) (DataSetSuffix,(Values))
("Comparison"("Set1 vs. Set2" Set1vsSet2)("Set1 vs. Set3" Set1vsSet3)("Set2 vs. Set4" Set2vsSet4));
Define VariableName /Group Center " " Style(Column)=Header
{Width=60mm Color=#112277 FontWeight=Bold TextAlign=R VerticalAlign=M};
Define DataSetSuffix /Across "Summary" Order=Data ;
Define Set1vsSet2/" " Computed Center Format=10.6 Style(Column)={Width=20mm Textalign=R};
Define Set1vsSet3/ " " Computed Center Format=10.6 Style(Column)={Width=20mm Textalign=R};
Define Set2vsSet4/ " " Computed Center Format=10.6 Style(Column)={Width=20mm Textalign=R} ;
Define Values / "" Analysis Sum Center Format=10.6 Style(column)={Width=20mm Textalign=R};
Compute Set1vsSet2;
Set1vsSet2=(_c2_-_c3_)/_c3_;
EndComp;
Compute Set1vsSet3;
Set1vsSet3=(_c5_-_c2_)/_c2_;
EndComp;
Compute Set2vsSet4;
Set2vsSet4=(_c5_-_c3_)/_c3_;
EndComp;
Run;
/*Data can come as below*/
Data Have2;
Length VariableName $ 50 DataSetSuffix $ 50 Values 8;
Infile Cards;
Input VariableName DataSetSuffix Values;
Cards;
Variable1 Set1 0.2
Variable2 Set1 0.4
Variable3 Set1 0.6
Variable1 Set2 0.3
Variable2 Set2 0.5
Variable3 Set2 0.7
;
Run;
/*Or data can come as below*/
Data Have3;
Length VariableName $ 50 DataSetSuffix $ 50 Values 8;
Infile Cards;
Input VariableName DataSetSuffix Values;
Cards;
Variable1 Set2 0.3
Variable2 Set2 0.5
Variable3 Set2 0.7
Variable1 Set3 0.4
Variable2 Set3 0.6
Variable3 Set3 0.8
Variable1 Set4 0.5
Variable2 Set4 0.7
Variable3 Set4 1.0
;
Run;
Data Have4;
Length VariableName $ 50 DataSetSuffix $ 50 Values 8;
Infile Cards;
Input VariableName DataSetSuffix Values;
Cards;
Variable1 Set5 0.4
Variable2 Set5 0.6
Variable3 Set5 0.8
Variable1 Set6 0.5
Variable2 Set6 0.7
Variable3 Set6 1.0
;
Run;
If you write Have2,Have3 or Have4 instead of Have1 in Proc Report statement, you can understand my problem, for Have1,Have2 and Have3 data sets, the desired output as below. I think I need macro-mend and macro Do-Loop in the macro-mend statment.
Can somebody help me, please?
Thank you
... View more