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

Hello everyone,

I have an array with eight dichotomous (yes,no) variables and I want to sum the variables such that I get a range of scores 0-8 (0 being none of them have any 'yes's' and 8 being all of the variables are yes. Then for any of the scores lower than 4 I would like to make missing. I am getting the SUM of all the variables as a dichotomous and not an 8 level score. Is there a better way to code this?

ARRAY ACE_ARRAY[8]  ACEPRISN2 ACEDIVRC2 ACEDEPRS2 ACESXAB ACESUBS ACEPUNCH2 ACESWEAR2 ACEHURT2;

SUM_ACESCORE = sum(of ACE_ARRAY[8]);

IF SUM_ACESCORE <= 4 then SUM_ACE = ' ';

Thank you,

Donald S.

1 ACCEPTED SOLUTION

Accepted Solutions
PhilC
Rhodochrosite | Level 12

I don't think the expression "of ACE_ARRAY[8]" is going to work for you like your are thinking it will.  NOW if the variables are always going to be adjacent in the dataset-- i.e. they have consecutive variable numbers (see proc contents) -- then you could use the syntax "of ACEPRISN2 -- ACEHURT2" (that's a double dash) and that would be the appropriate use of the "of" operator.

If you use the array then you want to use a do loop:

SUM_ACESCORE = 0;
do i=1 to 8; drop i;
  SUM_ACESCORE+ACE_ARRAY;
end;

View solution in original post

5 REPLIES 5
PhilC
Rhodochrosite | Level 12

I don't think the expression "of ACE_ARRAY[8]" is going to work for you like your are thinking it will.  NOW if the variables are always going to be adjacent in the dataset-- i.e. they have consecutive variable numbers (see proc contents) -- then you could use the syntax "of ACEPRISN2 -- ACEHURT2" (that's a double dash) and that would be the appropriate use of the "of" operator.

If you use the array then you want to use a do loop:

SUM_ACESCORE = 0;
do i=1 to 8; drop i;
  SUM_ACESCORE+ACE_ARRAY;
end;
daszlosek
Quartz | Level 8

Thank you PhilC, I believe this code works the way I want it to. From the proc freq, It seems odd to me that the Score starts at 8 and goes to 16. See below

The FREQ Procedure

       
83020.293020.29
910711.0413731.33
1021352.0735083.40
1134473.3469556.74
1253005.141225511.87
1378197.582007419.45
141204811.673212231.13
152150720.845362951.96
164957448.04103203100.00

Can I assume that the level "8" is 8/8 yes's, level "7" is 7/8 "yes's"  etc. and that level "16" is "no yes's"?

Thank you!

PhilC
Rhodochrosite | Level 12

The variables could be dichotomous, but have the values 1 and 2?  It's not clear to me.  We need a ~10 row sample of the data, a proc contents, and the code you used to add up the variables.

daszlosek
Quartz | Level 8

I am going to be doing my regression analysis in SUDAAN since it handles complex survey data faster and requires to be coded 1/2 instead of 0/1- yes, it is a pain. This is un-redacted data so I don't think I am allowed to share this information- will have to ask my boss. BUT I did just do some 2X2 tables to see if everything matches up and it appears to for the rows I have looked at so far.

PhilC
Rhodochrosite | Level 12

No pain is involved, if you see the data as 1's and 2's then its not odd, at all, that the range is 8 to 16.  Thanks for flagging my responses as helpful.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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