BookmarkSubscribeRSS Feed
amcr729
Fluorite | Level 6

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!

5 REPLIES 5
mkeintz
PROC Star

Could you provide the log, since there is nothing obviously wrong with the code you show, assuming it's part of a data step.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
amcr729
Fluorite | Level 6

Hello, 

Here is the log -- it shows (1) my recoding special codes (88 and 99) to missing (.) and then (2) the reverse coding code. I had no problem with (1) but am including it here in case that somehow sheds light on the problem with (2). 
Many thanks.
ballardw
Super User

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.

 

amcr729
Fluorite | Level 6

 

Sorry, I sent the wrong log with extraneous stuff. The attached log should be easier to  understand. 

ballardw
Super User

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?

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