BookmarkSubscribeRSS Feed
Dingdang
Fluorite | Level 6

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

3 REPLIES 3
ballardw
Super User

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;

Dingdang
Fluorite | Level 6

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

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 876 views
  • 0 likes
  • 2 in conversation