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.
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:
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:
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
8 | 302 | 0.29 | 302 | 0.29 |
---|---|---|---|---|
9 | 1071 | 1.04 | 1373 | 1.33 |
10 | 2135 | 2.07 | 3508 | 3.40 |
11 | 3447 | 3.34 | 6955 | 6.74 |
12 | 5300 | 5.14 | 12255 | 11.87 |
13 | 7819 | 7.58 | 20074 | 19.45 |
14 | 12048 | 11.67 | 32122 | 31.13 |
15 | 21507 | 20.84 | 53629 | 51.96 |
16 | 49574 | 48.04 | 103203 | 100.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!
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.
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.
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.
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!
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.