BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
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;
7 REPLIES 7
Doc_Duke
Rhodochrosite | Level 12
An easy way to do this for dichotomous variables is to use code like

skills(i) = 1 - skills(i);
R_A_G_
Calcite | Level 5
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
Doc_Duke
Rhodochrosite | Level 12
Try it.

1 - 0 = 1
1 - 1 = 0
R_A_G_
Calcite | Level 5
I feel dumb 😞
sorry
and thanks Doc
R_A_G_
Calcite | Level 5
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;
RickM
Fluorite | Level 6
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;
R_A_G_
Calcite | Level 5
THANK YOU
It worked!!

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1851 views
  • 0 likes
  • 3 in conversation