BookmarkSubscribeRSS Feed
harigottala0
Fluorite | Level 6

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...

10 REPLIES 10
Reeza
Super User
How is distance calculated based on that data?
What is the formula?

Please show what you've tried.
harigottala0
Fluorite | Level 6

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;

Reeza
Super User
But G1 has two values, G2 has two values, how do you subtract G1-G2 for both values?
Which value under G1 is G1?

If that 2x3 data set was your input what EXACTLY is your output?
harigottala0
Fluorite | Level 6

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 

Reeza
Super User

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 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 


 

harigottala0
Fluorite | Level 6

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

Reeza
Super User
do i=1 to dim(_in);
_out(i) = _in(_n_) - _in(i);
end;
harigottala0
Fluorite | Level 6

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;

ERROR: Array subscript out of range at line 83 column 23.
G1=190 G2=100 G3=200 X1=90 X2=-100 X3=. i=3 _ERROR_=1 _N_=1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.ONE.
WARNING: The data set WORK.TWO may be incomplete. When this step was stopped there were 0 observations and 7 variables.
WARNING: Data set WORK.TWO was not replaced because this step was stopped.
ChrisNZ
Tourmaline | Level 20

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;

 

ballardw
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 10 replies
  • 2233 views
  • 1 like
  • 4 in conversation