## Another problem

Regular Contributor
Posts: 161

# Another problem

I was wondering how I can reverse the value of my dichotomous items that are 0 to 1 and those that are 1 to 0.

I have 4 items I am doing this within a Macro and it is not working

DATA WR;
set Matrix;
DO i=1 TO &numi;

if skills(i)=0 THEN skills(i)=1;
ELSE if SKILLS(i)=1 then skills(i)=0;
end;
run;
Posts: 2,125

## Re: Another problem

An easy way to do this for dichotomous variables is to use code like

skills(i) = 1 - skills(i);
Regular Contributor
Posts: 161

## Re: Another problem

Thank you Doc,

But what if the skill=0

my data looks like this

skill1 kills2 skills3 skills4
0 1 1 0
1 0 1 1

and so on,

I need to change all 1's to 0 and all 0's to 1

Thank you
Posts: 2,125

## Re: Another problem

Try it.

1 - 0 = 1
1 - 1 = 0
Regular Contributor
Posts: 161

## Re: Another problem

I feel dumb
sorry
and thanks Doc
Regular Contributor
Posts: 161

## Re: Another problem

help!!

I am getting the following error,

DATA WR;
set Matrix;
do i=1 to 4;

skills(i)=1- skills(i);
END;
run;

I am getting the following error why?

16821 skills(i)=1- skills(i);
------
68
ERROR: Undeclared array referenced: skills.
ERROR: Variable skills has not been declared as an array.
ERROR 68-185: The function SKILLS is unknown, or cannot be accessed.

16822 END;
Regular Contributor
Posts: 165

## Re: Another problem

You need to declare an array before using it.

DATA WR;
set Matrix;
array skills(4);
do i=1 to 4;
skills(i)=1- skills(i);
END;
run;
Regular Contributor
Posts: 161

## Re: Another problem

THANK YOU
It worked!!
Discussion stats
• 7 replies
• 249 views
• 0 likes
• 3 in conversation