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!!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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