Hello all,
I am reverse coding a subset of items in a scale using an array and a quantitative transformation. The response options for the scale items are: (1) totally disagree, (2) disagree, (3) agree, and (4) totally agree (there are also special codes for "don't know" and "refused" answers, but I have already recoded those to missing (i.e. "."). After I run my code and check my work by looking at frequency tables however, I can see that something is wrong because the tables are completely empty and show all observations to be missing. I am wracking my brain but cannot figure out why this is happening. Here is my code for the reverse coding:
ARRAY new (14)
AETS19_09_1nr
AETS19_10_1nr
AETS19_11_1nr
AETS19_12_1nr
AETS19_13_1nr
AETS19_14_1nr
AETS19_15_1nr
AETS19_09_2nr
AETS19_10_2nr
AETS19_11_2nr
AETS19_12_2nr
AETS19_13_2nr
AETS19_14_2nr
AETS19_15_2nr;
ARRAY old (14)
AETS19_09_1n
AETS19_10_1n
AETS19_11_1n
AETS19_12_1n
AETS19_13_1n
AETS19_14_1n
AETS19_15_1n
AETS19_09_2n
AETS19_10_2n
AETS19_11_2n
AETS19_12_2n
AETS19_13_2n
AETS19_14_2n
AETS19_15_2n;
Do i=1 to 14;
If old (i) =. then new (i)=.;
Else new (i) = 5 - old (i);
END;
DROP I;
RUN;
Many thanks in advance to anyone who can identify my error!
Could you provide the log, since there is nothing obviously wrong with the code you show, assuming it's part of a data step.
Hello,
You are using the same variables multiple times. The data set IPV is referenced as data IPV; 15 times. So it really isn't very possible to identify where anything is happening.
Provide a small data set with values for just a couple of variables that show the desired behavior similar to
data example; input AETS19_09_1n AETS19_10_1n; datalines; 1 2 3 4 . 1 1 . . . ; run;
You might be interesting in knowing that
do i=1 to dim(new); new (i) = 5 - old (i); END;
behaves exactly the same as
do i=1 to dim(new); If old (i) =. then new (i)=.; Else new (i) = 5 - old (i); END;
Any addition, subtraction or multiplication involving a missing value results in missing.
It appears that you tried the above but left an ELSE in the code:
352 Do i=1 to 14; 353 /*If old (i) =. then new (i)=.;*/ 354 Else new (i) = 5 - old (i); ---- 160 ERROR 160-185: No matching IF-THEN clause. 355 END; 356 DROP I; 357 RUN;
at which point data ipv was not replaced so everything after that is suspect but the proc freq executed at line 359 was run against the data ipv created starting at line 269.
Sorry, I sent the wrong log with extraneous stuff. The attached log should be easier to understand.
And some example data in a data step where AETS19_09_1n is not missing that when you run the code generates missing values for
AETS19_09_1nr?
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 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.