BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Rou
Obsidian | Level 7 Rou
Obsidian | Level 7

Hello all,

 

I need help calculating the raw total of four variables (promis_pa_scale1, promis_pa_scale3, promis_pa_scale4, promis_pa_scale5). Each variable is coded 1,2,3,4,5 or 99. Not sure how to proceed. 

Here is a screen shot of the assignment:

Creating an outcome score:

  1. Sum a total raw score 
  2. Use the table provided to convert the total raw score into a t-score for each participant

Rou_0-1657594440332.jpeg

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If your value of 99 means that the data is actually missing, not appropriate, not answered or anything close to those then it is almost certain that you do not want to include them in any sum.

 

If the 1, 2, 3, 4 and 5 are not actually interval measurements but code values such as on an agreement scale or possibly categories (very good, good, neutral, poor, very poor) then summing values is very questionable in general.

 

I think you are looking for something similar to:

data want; 
   set have;
   array p (*) promis_pa_scale1 promis_pa_scale3 - promis_pa_scale5;
   /* set the 99 to missing*/
   do i=1 to dim(p);
      if p[i]=99 then p[i]=.;
   end;
   ptotal = sum(promis_pa_scale1, promis_pa_scale3, promis_pa_scale4, promis_pa_scale5);
   /* ugly, long and robust but all I am willing to do with PICTURES of values*/
   if ptotal=4 then tscore = 32.3;
   else if ptotal = 5 then tscore = 37.3;
   else if ptotal = 6 then tscore = 39.5;
   /* follow the pattern until*/
   else if ptotal =20 then tscore = 68.4;
run;

If you have not seen Array code before the array definition creates a reference to a group of variables of the same type. The array above is named P. If you have a variable named P there will be a conflict as array names cannot duplicate variables in the data set. You reference which value using arrayname(indexnumber). The above array has 4 elements and P[3] would reference the third variable in the list or promis_pa_scale4. The hyphen between names is a sequential list builder.

The DIM function returns the number of elements defined in an array so that you can iterate over only the variables present. So the Do loop removes the 99 values and sets them to missing. Since your Tscore values do not include any values larger than 20 then 99 must be right out.

 

There a multiple statistic functions such as Sum, Mean, Max, Min, Range, STD, Median and others that will allow you to get such a statistic for variables on a single record. Note that missing values are handled properly in such functions. If one of the values of 4 is missing then 3 are used to sum and 3 would the denominator for Mean calculations.

 

There are multiple ways to do a look up in SAS. Common ways include Informats created with Proc Format, joining data sets on specified values, If/then/else logic (shown), Select / when (really a shorter way of if/then/else); Update/modify/merge sometimes, Hash code.

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

If your value of 99 means that the data is actually missing, not appropriate, not answered or anything close to those then it is almost certain that you do not want to include them in any sum.

 

If the 1, 2, 3, 4 and 5 are not actually interval measurements but code values such as on an agreement scale or possibly categories (very good, good, neutral, poor, very poor) then summing values is very questionable in general.

 

I think you are looking for something similar to:

data want; 
   set have;
   array p (*) promis_pa_scale1 promis_pa_scale3 - promis_pa_scale5;
   /* set the 99 to missing*/
   do i=1 to dim(p);
      if p[i]=99 then p[i]=.;
   end;
   ptotal = sum(promis_pa_scale1, promis_pa_scale3, promis_pa_scale4, promis_pa_scale5);
   /* ugly, long and robust but all I am willing to do with PICTURES of values*/
   if ptotal=4 then tscore = 32.3;
   else if ptotal = 5 then tscore = 37.3;
   else if ptotal = 6 then tscore = 39.5;
   /* follow the pattern until*/
   else if ptotal =20 then tscore = 68.4;
run;

If you have not seen Array code before the array definition creates a reference to a group of variables of the same type. The array above is named P. If you have a variable named P there will be a conflict as array names cannot duplicate variables in the data set. You reference which value using arrayname(indexnumber). The above array has 4 elements and P[3] would reference the third variable in the list or promis_pa_scale4. The hyphen between names is a sequential list builder.

The DIM function returns the number of elements defined in an array so that you can iterate over only the variables present. So the Do loop removes the 99 values and sets them to missing. Since your Tscore values do not include any values larger than 20 then 99 must be right out.

 

There a multiple statistic functions such as Sum, Mean, Max, Min, Range, STD, Median and others that will allow you to get such a statistic for variables on a single record. Note that missing values are handled properly in such functions. If one of the values of 4 is missing then 3 are used to sum and 3 would the denominator for Mean calculations.

 

There are multiple ways to do a look up in SAS. Common ways include Informats created with Proc Format, joining data sets on specified values, If/then/else logic (shown), Select / when (really a shorter way of if/then/else); Update/modify/merge sometimes, Hash code.

 

 

Rou
Obsidian | Level 7 Rou
Obsidian | Level 7

@ballardw thank you the response and explanation. The 1,2,3,4,5 are code values.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 701 views
  • 1 like
  • 2 in conversation