Dear All,
I had the input data in the format which is mentioned in Data file.
Output:
Desired output in the below format
Difference bewtween G1 and remaining G2,G3...
Dear Reeza,
Just difference between G1-G2,G1-G3....ETC
data one;
input G1 G2 G3;
cards;
190 100 200
233 400 400
;
run;
data two;
set one;
array sbparray [3] G1 - G3;
array rbparray [3] G1 - G3;
array s[3] X1 - X3;
do i = 1 to 3;
do j= 1 to 3;
S[i] = sbparray [i] -rbparray [j];
end;
end;
run;
Dear Reeza,
G1 G2 G3
190 100 200
233 400 400
o/p should be :
X1 X2 X3
190-190=0 190-100=-90 190-200=-10
233-233=0 233-400=-167 233-400=-167
This doesn't match your Excel file requirements but is much easier to accomplish.
data have;
input G1 G2 G3;
cards;
190 100 200
233 400 400
;;;;
run;
data want;
set have;
array _in(3) G1-G3;
array _out(3) X1-X3;
do i=1 to dim(_in);
_out(i) = _in(i) - _in(max(i-1, 1));
end;
run;
@harigottala0 wrote:
Dear Reeza,
G1 G2 G3
190 100 200
233 400 400o/p should be :
X1 X2 X3
190-190=0 190-100=-90 190-200=-10
233-233=0 233-400=-167 233-400=-167
Dear Reeza,
Yes, I need the output which match with excel file.
G1 G2 G3
190 100 200
233 400 400
o/p should be :
X1 X2 X3
190-190=0 (G1-G1) 190-100=-90 (G1-G2) 190-200=(G1-G3)
400-233=167 (G2-G1) 400-400=0(G2-G2) 400-400=(G2-G3)
Thank you
do i=1 to dim(_in);
_out(i) = _in(_n_) - _in(i);
end;
Dear Reeza,
I have tried this way also it is throwing a error .
data one;
input G1 G2 G3;
cards;
190 100 200
233 400 400
;
run;
data two;
set one;
array sbparray [3] G1 - G3;
array s[3] X1 - X3;
do i = 1 to 3;
S[i] = sbparray [i] -sbparray [i+1];
end;
run;
From what you wrote, it seem you want:
data TWO;
set ONE;
array SBPARRAY [3] G1 - G3;
array S[3] X1 - X3;
do I = 1 to 3;
S[I] = SBPARRAY [1] - SBPARRAY [I];
end;
run;
Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.