Comparing Variables that are in different Data Sets

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Comparing Variables that are in different Data Sets

Suppose 3 data sets with the names A, B, and C, which had been previously created.
The Data Set A contains only the variable named A1 with several observations.
The Data Set C contains only the variable named C1 with several observations.
The Data Set B has 2 variables, B1 and B2, but only with 2 observations.

Data Set      A              B      C      Result for D
VariablesA1B1B2C1D1D2
Observation 14-38-24-0.15
Observation 2-45-619-3 -0.23
Observation 323 -5 -0.38
Observation 41 510.38
Observation 52 920.69
Observation 6-56 -13 -1
Observation 7-4 1 0.07
Observation 8. ...
Observation 9. ...
Observation 10. ...

1- I want to compare if [A1 (all observations)] is greater than ([B1 - observation 1] = -3) & less than ([B2 - observation 1] = 8). If so, save the values ​​into a new Data Set, named  D, as variable D1 (A1 values ​​that do not satisfy the conditions must be empty in D1).

2- I want to divide all the observations of C1 per (B1 + B2 -> observation 2 ->  ((-6)+(19)) = 13. Save the result as variable D2 on Data Set D.

Thanks for your attention!


Accepted Solutions
Solution
‎07-02-2013 08:19 AM
Super Contributor
Posts: 282

Re: Comparing Variables that are in different Data Sets

Hi,

Does the following give you what you want?:

data a;

  input a1;

  datalines;

4

-45

23

1

2

-56

-4

.

.

.

;

data b;

  input b1 b2;

  datalines;

-3 8

-6 19

;

data c;

  input c1;

  datalines;

-2

-3

-5

5

9

-13

1

.

.

.

;

data _null_;

  set b;

  if _n_=1 then

  do;

    call symputx('b1_1',b1);

    call symputx('b1_2',b2);

  end;

  else

    call symputx('b2sum',b1+b2);

run;

data d(keep=d1 d2);

  set a;

  d1=ifn(a1 gt &b1_1 and a1 lt &b1_2,a1,.);

  set c;

  d2=round(c1/&b2sum,0.01);

run;

Regards,

Amir

Message was edited by: Amir Malik - changed some formatting.

View solution in original post


All Replies
Solution
‎07-02-2013 08:19 AM
Super Contributor
Posts: 282

Re: Comparing Variables that are in different Data Sets

Hi,

Does the following give you what you want?:

data a;

  input a1;

  datalines;

4

-45

23

1

2

-56

-4

.

.

.

;

data b;

  input b1 b2;

  datalines;

-3 8

-6 19

;

data c;

  input c1;

  datalines;

-2

-3

-5

5

9

-13

1

.

.

.

;

data _null_;

  set b;

  if _n_=1 then

  do;

    call symputx('b1_1',b1);

    call symputx('b1_2',b2);

  end;

  else

    call symputx('b2sum',b1+b2);

run;

data d(keep=d1 d2);

  set a;

  d1=ifn(a1 gt &b1_1 and a1 lt &b1_2,a1,.);

  set c;

  d2=round(c1/&b2sum,0.01);

run;

Regards,

Amir

Message was edited by: Amir Malik - changed some formatting.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 166 views
  • 1 like
  • 2 in conversation