BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kim2009
Calcite | Level 5

Greetings - 

I'm trying to figure out how to transform 3 variables so that the range is from 0-100. 

Here are the 3 variables that can also be found in the attached xlsx file. The sum of the 3 variables range between 3 (min) and 12 (max).  

 

CTIOne CTITwoCITThree

 

Responses for each of the variables were scored as

Strongly Disagree =1; Disagree =2; Agree =3; Strongly Agree =4; 9=Don't know; 99=Missing 

 

I found an SPSS resource on this topic online but didn't find any SAS documentation that was straightforward. Here are the steps outlined in the SPSS document. 

 

1. Calculate the sum of responses across the 3 variables (excluding values of 9 and 99) - New variable name = CTI3Sum 

2. Count the number of questions answered, i.e. 1-3 (excluding values of 9 and 99) - New variable name  = CTI3Ct

3. Calculate the mean response - New variable name = CTI3Mean which is calculated by CTI3Sum/CTI3Ct

4. Use linear  transformation to convert to 0-100 score  - New variable name = CTI3_NewScale

 

Any guidance on how to perform these steps in SAS would be greatly appreciated. 

 

Best,

Kim

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Kim2009 and welcome to the SAS Support Communities!

 

The calculation in SAS is relatively easy because the MEAN function excludes missing values by default, hence combines steps 1 - 3. So we only need to replace values 9 and 99 by missing values before calling the MEAN function. This is demonstrated below using artificial test data created in a preliminary DATA step because I don't have Excel on my SAS workstation. (Many experts here won't even download Excel files due to security concerns.)

 

/* Create test data for demonstration */

data have;
call streaminit(27182818);
length ID 8;
array v[6]  _temporary_ (1:4 9 99);
array p1[6] _temporary_ (.1 .2 .4 3*.1);
array p2[6] _temporary_ (2*.05 3*.25 .15);
array p3[6] _temporary_ (2*.15 2*.3 2*.05);
array score[*] CTIOne CTITwo CTIThree;
do ID=1 to 500;
  score[1]=v[rand('table', of p1[*])];
  score[2]=v[rand('table', of p2[*])];
  score[3]=v[rand('table', of p3[*])];
  output;
end;
run;

/* Create scaled mean score CTI3_NewScale (between 0 and 100) */

data want(drop=_:);
set have;
array score[*] CTIOne CTITwo CTIThree;
array _nmCTI[3];
do _i=1 to dim(score);
  if score[_i] in (1:4) then _nmCTI[_i]=score[_i];
  else if score[_i] in (9, 99) then _nmCTI[_i]=.m;
  else put 'WAR' 'NING: Invalid score for ID ' id  +(-1) ': ' score[_i]=;
end;
if n(of _nmCTI[*]) then CTI3_NewScale=(mean(of _nmCTI[*])-1)*100/3;
else CTI3_NewScale=.;
run;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Kim2009 and welcome to the SAS Support Communities!

 

The calculation in SAS is relatively easy because the MEAN function excludes missing values by default, hence combines steps 1 - 3. So we only need to replace values 9 and 99 by missing values before calling the MEAN function. This is demonstrated below using artificial test data created in a preliminary DATA step because I don't have Excel on my SAS workstation. (Many experts here won't even download Excel files due to security concerns.)

 

/* Create test data for demonstration */

data have;
call streaminit(27182818);
length ID 8;
array v[6]  _temporary_ (1:4 9 99);
array p1[6] _temporary_ (.1 .2 .4 3*.1);
array p2[6] _temporary_ (2*.05 3*.25 .15);
array p3[6] _temporary_ (2*.15 2*.3 2*.05);
array score[*] CTIOne CTITwo CTIThree;
do ID=1 to 500;
  score[1]=v[rand('table', of p1[*])];
  score[2]=v[rand('table', of p2[*])];
  score[3]=v[rand('table', of p3[*])];
  output;
end;
run;

/* Create scaled mean score CTI3_NewScale (between 0 and 100) */

data want(drop=_:);
set have;
array score[*] CTIOne CTITwo CTIThree;
array _nmCTI[3];
do _i=1 to dim(score);
  if score[_i] in (1:4) then _nmCTI[_i]=score[_i];
  else if score[_i] in (9, 99) then _nmCTI[_i]=.m;
  else put 'WAR' 'NING: Invalid score for ID ' id  +(-1) ': ' score[_i]=;
end;
if n(of _nmCTI[*]) then CTI3_NewScale=(mean(of _nmCTI[*])-1)*100/3;
else CTI3_NewScale=.;
run;
Kim2009
Calcite | Level 5

Works like a charm! Thanks a million for your help. 

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!

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
  • 2 replies
  • 1206 views
  • 0 likes
  • 2 in conversation