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


Hi,

I have a variable set with variables q1_0_on, q1_0_ab, q1_1_on, q1_1_ab ... etc. all the way to q1_12_on, q1_12_ab.

Essentially what i'd like to do is to recode it into a different variable with a scale (1,0,-1) with an array.

q1_0 = 0;

if q1_0_on=1 and q1_0_ab=0 then q1_0=1;

if q1_0_on=0 and q1_0_ab=1 then q1_0=-1 ;

i could duplicate the code above 12 times but i was hoping there's an easy way with an array.

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Looks like you need 3 arrays.

Array Q_on q1_0_on q1_1_on (continue adding until q1_12_on;

Array Q_ab q1_0_ab q1_1_ab  (ditto);

array Q q1_0 q1_1 ... q1_12;

do i = 1 to dim (Q);

     Q = 0;

     if Q_on=1 and Q_ab=0 then Q=1;

     if Q_on=0 and Q_ab=1 then Q=-1;

end;

drop i;

View solution in original post

1 REPLY 1
ballardw
Super User

Looks like you need 3 arrays.

Array Q_on q1_0_on q1_1_on (continue adding until q1_12_on;

Array Q_ab q1_0_ab q1_1_ab  (ditto);

array Q q1_0 q1_1 ... q1_12;

do i = 1 to dim (Q);

     Q = 0;

     if Q_on=1 and Q_ab=0 then Q=1;

     if Q_on=0 and Q_ab=1 then Q=-1;

end;

drop i;

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
  • 1 reply
  • 817 views
  • 0 likes
  • 2 in conversation