<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Recode variables using if then across multiple variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/475666#M71177</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219315"&gt;@ecommon&lt;/a&gt; and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry that your question hasn't been answered yet (probably due to yesterday's U.S. holiday).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you have a lot of variables, as it seems, a dataset in "wide" format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code example could be simplified to something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if SecondaryObserver_S1 = 0 then call missing(of PO_S1_Q[*]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where PO_S1_Q is the name of an array (to be declared) consisting of the 21 variables on the right-hand side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case this will set those 21 variables to missing only if the condition &lt;FONT face="courier new,courier"&gt;SecondaryObserver_S1 = 0&lt;/FONT&gt; is met &lt;EM&gt;for the same observation&lt;/EM&gt;. Since you say that it's not working, the situation in your data is probably different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide sample data in the form of a data step to clarify your current data structure and what the result should look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example which you can modify as needed. (I think it will suffice to consider only &lt;EM&gt;three&lt;/EM&gt; questionnaire items and &lt;EM&gt;two&lt;/EM&gt; sessions. Also, I suggest we shorten the variable names for the example.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id so_s1 po_s1_q1 po_s1_q2 po_s1_q3 so_s2 po_s2_q1 po_s2_q2 po_s2_q3;
cards;
101 0 2 1 0 1 1 2 2
102 1 0 . 2 0 0 1 1
;

data want;
input id so_s1 po_s1_q1 po_s1_q2 po_s1_q3 so_s2 po_s2_q1 po_s2_q2 po_s2_q3;
cards;
101 0 . . . 1 1 2 2
102 1 0 . 2 0 . . .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jul 2018 15:13:04 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2018-07-05T15:13:04Z</dc:date>
    <item>
      <title>Recode variables using if then across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/475473#M71164</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am intersted in recoding or creating a new variable using logic (if/then statements) from another variable? My current&amp;nbsp;code is not working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Summary of data set:&amp;nbsp; I have an 21 item measure (Q1-Q21), with 25% of sessions (S1-12)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SecondaryObserver_S1 (can be 0 or 1) - was there a secondary observer for first sessions&lt;/P&gt;&lt;P&gt;PrimaryObserver_S1_Q1 (can be 0, 1, 2, or .) - Likert type variable for session 1 question 1&lt;/P&gt;&lt;P&gt;PrimaryObserver&lt;SPAN&gt;_S1_&lt;/SPAN&gt;Q2&amp;nbsp;&lt;SPAN&gt;(can be 0, 1, 2, or .)- Likert type variable for session 1 question 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;PrimaryObserver&lt;SPAN&gt;_S1_&lt;/SPAN&gt;Q.21&amp;nbsp;&lt;SPAN&gt;(can be 0 or 1)&amp;nbsp; -etc&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;SecondaryObserver_S12 (can be 0 or 1)&lt;SPAN&gt;- was there a secondary observer for second session&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;PrimaryObserver_S12_Q1 (can be 0, 1, 2, or .) -&amp;nbsp;Likert type variable for session&amp;nbsp;2 question 1&lt;/P&gt;&lt;P&gt;PrimaryObserver&lt;SPAN&gt;_S12_&lt;/SPAN&gt;Q2&amp;nbsp;&lt;SPAN&gt;(can be0, 1, 2, or .) - etc&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;PrimaryObserver&lt;SPAN&gt;_S12_&lt;/SPAN&gt;Q.21&amp;nbsp;&lt;SPAN&gt;(0, 1, 2, or .)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would like to to&amp;nbsp;retain primary observer's data only if there was a secondary observer.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I tried:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF SecondaryObserver_S1&amp;nbsp;= 0 THEN&amp;nbsp;PrimaryObserver_S1_Q1&amp;nbsp; = .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IF SecondaryObserver_S1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0 THEN&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;PrimaryObserver_S1_Q2&amp;nbsp; = .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IF SecondaryObserver_S1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0 THEN&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;PrimaryObserver_S1_Q21 = .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The code runs, but it is not recoding&amp;nbsp;any variables. I have used if/then/else statements for recoding a variable&amp;nbsp;using the logic/conditions of that variable, but never using logic of other variables. Is this possible, or are there any suggested solutions?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jul 2018 17:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/475473#M71164</guid>
      <dc:creator>ecommon</dc:creator>
      <dc:date>2018-07-04T17:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables using if then across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/475666#M71177</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/219315"&gt;@ecommon&lt;/a&gt; and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry that your question hasn't been answered yet (probably due to yesterday's U.S. holiday).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you have a lot of variables, as it seems, a dataset in "wide" format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code example could be simplified to something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if SecondaryObserver_S1 = 0 then call missing(of PO_S1_Q[*]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where PO_S1_Q is the name of an array (to be declared) consisting of the 21 variables on the right-hand side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any case this will set those 21 variables to missing only if the condition &lt;FONT face="courier new,courier"&gt;SecondaryObserver_S1 = 0&lt;/FONT&gt; is met &lt;EM&gt;for the same observation&lt;/EM&gt;. Since you say that it's not working, the situation in your data is probably different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide sample data in the form of a data step to clarify your current data structure and what the result should look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example which you can modify as needed. (I think it will suffice to consider only &lt;EM&gt;three&lt;/EM&gt; questionnaire items and &lt;EM&gt;two&lt;/EM&gt; sessions. Also, I suggest we shorten the variable names for the example.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id so_s1 po_s1_q1 po_s1_q2 po_s1_q3 so_s2 po_s2_q1 po_s2_q2 po_s2_q3;
cards;
101 0 2 1 0 1 1 2 2
102 1 0 . 2 0 0 1 1
;

data want;
input id so_s1 po_s1_q1 po_s1_q2 po_s1_q3 so_s2 po_s2_q1 po_s2_q2 po_s2_q3;
cards;
101 0 . . . 1 1 2 2
102 1 0 . 2 0 . . .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 15:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/475666#M71177</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-07-05T15:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables using if then across multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/476905#M71247</link>
      <description>&lt;P&gt;That is an accurate depiction of my data structure. The array and %name feature were both successful in recoding my variables. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 18:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Recode-variables-using-if-then-across-multiple-variables/m-p/476905#M71247</guid>
      <dc:creator>ecommon</dc:creator>
      <dc:date>2018-07-10T18:47:54Z</dc:date>
    </item>
  </channel>
</rss>

