DATA Step, Macro, Functions and more

comparing the values of 2 groups of variables in the same data set as plausibility check

Reply
Contributor
Posts: 57

comparing the values of 2 groups of variables in the same data set as plausibility check

Hi,

I want to compare the values of 2 groups of variables in the same data set "work.have". I've saved the two groups of variables in two macro variables &gIS and &gSHOULD with proc sql. Each group has 40 variables and each variable has 60 observations (persons). The data was sorted, so the counterparty of the 1st variable in gIS is just the 1st variable in gSHOULD and so on. The aim is to do a plausibility check. If the data was right, then the values of the variables in gIS should be bigger than the ones in gSHOULD.

What i want to get is a dataset with 61 rows and 41 columns that looks like this:

                 Comparison Var1 from gIS with Var1 from gSHOULDComparison Var2 from gIS with Var2 from gSHOULDComparison Var 3 from gIS with Var3 from gSHOULD

Person 1

000
Person 2100
Person 3001

The headers are a bit awkward. I think i have to name them another way. but the aim is to have a '0', where the condition gIS>gSHOULD got satisfied and 1 otherwise. So the '1' is like a warning, that sth. is wrong with the data there.

I've only worked with vectors before and since the outcoming is actually a matix, I dont know how to write my script.

I hope I made my task clear. Any help is very much appreciated!!

BR  Dingdang

Super User
Posts: 11,343

Re: comparing the values of 2 groups of variables in the same data set as plausibility check

I think you're coding of 0 for true and 1 for false a tad odd but if I understand your requirement something like this may be what you are asking for:

data want;

     set have;

     array g &gls;

     array should &gShould;

     array compare {40}; /* 40 since you say that's how many variables are in each of the macro variables*/

     do _i_=1 to dim(g);

          compare[_i_] = gls[_i_] le should[_i_];

     end;

run;

Contributor
Posts: 57

Re: comparing the values of 2 groups of variables in the same data set as plausibility check

hi Balladw,

thanks for your code, tried it out just now, but there is an error saying: arrayindex not in allowed range in row .. column y. and i got in log the names and the values of the variables printed out. like this:

RTF00_0080_040=ABC Bank RTF00_0100_040=2 RTF00_0120_040=1234567 RTF00_0160_040=2 RTF00_0180_040=3 RTF00_0200_040=31/12/2012 RTF00_0240_040=Max Mustermann RTF00_0260_040=1111-1111111 RTF00_0280_040=max.mustermann@musterbank.de RTF01_0060_090=4 RTF01_0100_030=10 RTF01_0110_030=4 RTF01_0120_030=7 RTF01_0130_030=8 RTF01_0140_030=8 RTF01_0150_030=7 RTF01_0160_030=7 RTF01_0170_030=4 RTF01_0180_030=4 RTF01_0190_030=4 RTF01_0100_050=2 RTF01_0110_050=10....

the variables in the data want are just the variables in gIS and gSHOULD and there are no observations.

actually i wrote sth. similar to your code and i think the problem is the dimension, or? somehow i need a matrix in the end, not a column or sth. but i am not sure if this was the problem.

BR  Dingdang

Super User
Posts: 11,343

Re: comparing the values of 2 groups of variables in the same data set as plausibility check

If you are working in IML then you probably need to say so and post in the IML discussion group.

Otherwise I think we need to go back a few steps to describe what is actually in your macro variables and what you wnat done.

Ask a Question
Discussion stats
  • 3 replies
  • 221 views
  • 0 likes
  • 2 in conversation