<?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: Simplify repetitive if-then statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842244#M333038</link>
    <description>&lt;P&gt;Can you provide an example of what your data set looks like as data step code.?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a tad concerned that you are assigning values to the same variable based on multiple variables and if any of your observations have more than one "set" of values that your example code may be incomplete as you maybe should have multiple difference results.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2022 00:22:51 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-11-03T00:22:51Z</dc:date>
    <item>
      <title>Simplify repetitive if-then statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842232#M333036</link>
      <description>&lt;P class=""&gt;Completely new to this so very thankful for your help.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;In a crossover study with Treatments X, Y, and Z (order is randomly assigned), under each treatment there are repetitive measurements at 3 different time points (Time 1, 2, and 3). I need to find the difference of time 2 and 1 under treatments X and Y and then the difference between those two values. So something to the effect of (Y2-Y1) - (X2-X1). I used wide data format and my codes work but they are highly repetitive because X/Y occur randomly in each treatment period:&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;if treatment_1 = "X" then difference_X = treatment1_time2 - treatment1_time1;&lt;/P&gt;&lt;P class=""&gt;if treatment_2 = "X" then difference_X = treatment2_time2 - treatment2_time1;&lt;/P&gt;&lt;P class=""&gt;if treatment_3 = "X" then difference_X = treatment3_time2 - treatment3_time1;&lt;/P&gt;&lt;P class=""&gt;if treatment_1 = "Y" then difference_Y = treatment1_time2 - treatment1_time1;&lt;/P&gt;&lt;P class=""&gt;if treatment_2 = "Y" then difference_Y = treatment2_time2 - treatment2_time1;&lt;/P&gt;&lt;P class=""&gt;if treatment_3 = "Y" then difference_Y = treatment3_time2 - treatment3_time1;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;and then I subtracted difference_X from difference_Y. I tried using array and do loops but since treatment X can occur in treatment periods 1, 2, or 3, I couldn't make it work with fewer lines of codes. Would something like this be more efficiently accomplished using the long format? Or is there a data formatting/cleaning function that I need to learn?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 23:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842232#M333036</guid>
      <dc:creator>rinentert</dc:creator>
      <dc:date>2022-11-02T23:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify repetitive if-then statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842244#M333038</link>
      <description>&lt;P&gt;Can you provide an example of what your data set looks like as data step code.?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a tad concerned that you are assigning values to the same variable based on multiple variables and if any of your observations have more than one "set" of values that your example code may be incomplete as you maybe should have multiple difference results.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 00:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842244#M333038</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-03T00:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify repetitive if-then statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842246#M333039</link>
      <description>&lt;P&gt;Hi ballardw, thank you so much for your response. The data set looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data try;
input treatment_1 $ treatment_2 $ treatment_3 $ treatment_1_time1 treatment_1_time2 treatment_1_time3 treatment_2_time1 treatment_2_time2 treatment_2_time3 treatment_3_time1 treatment_3_time2 treatment_3_time3;
datalines;
X Y Z 3.4 4.2 5.3 8.9 7.4 3.5 2.7 2.8 9.2
Y Z X 8.5 7.2 6.6 4.0 1.3 6.4 6.3 2.5 5.1
Z X Y 2.1 7.7 5.7 5.8 7.0 4.2 1.0 1.2 7.0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The values under treatment_# represent the first, second, and third period of a crossover study during which X/Y/Z could be administered. The values under treatment_#_time# represent the outcome at that time of measurement. I apologize for how confusing my naming convention is. My goal here is to find the difference between treatment_1_time1 and treatment_1_time2 only when X and Y are administered.&amp;nbsp;The ultimate goal is to evaluate the effects of treatment order on outcome like in a traditional AB/BA crossover study. But unlike a simple 2x2 study there is the addition of a third treatment and multiple measurements during each treatment period.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 01:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842246#M333039</guid>
      <dc:creator>rinentert</dc:creator>
      <dc:date>2022-11-03T01:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify repetitive if-then statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842254#M333046</link>
      <description>&lt;P&gt;Sounds like you mean you have this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input subject leg treatment $ time result ;
datalines;
1 1 X 1 3.4
1 1 X 2 4.2
1 1 X 3 5.3
1 2 Y 1 8.9
1 2 Y 2 7.4
1 2 Y 3 3.5
1 3 Z 1 2.7
1 3 Z 2 2.8
1 3 Z 3 9.2
2 1 Y 1 8.5
2 1 Y 2 7.2
2 1 Y 3 6.6
2 2 Z 1 4
2 2 Z 2 1.3
2 2 Z 3 6.4
2 3 X 1 6.3
2 3 X 2 2.5
2 3 X 3 5.1
3 1 Z 1 2.1
3 1 Z 2 7.7
3 1 Z 3 5.7
3 2 X 1 5.8
3 2 X 2 7
3 2 X 3 4.2
3 3 Y 1 1
3 3 Y 2 1.2
3 3 Y 3 7
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2022 04:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842254#M333046</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-03T04:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify repetitive if-then statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842316#M333075</link>
      <description>&lt;P&gt;Hi Tom, yes this really clarifies what I was trying to convey, thank you! I do have a version of my data that looks like this, however, I'm still at a loss as to how I would output a column that subtracts time 1 results from time 2 only when treatments X and Y are administered and then find the differences between those two in the long format. Down the line when I conduct data analysis comparing this "result difference" between the XY/YX groups, wouldn't the wide format that has one "result difference" per subject be easier to work with?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2022 13:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-repetitive-if-then-statements/m-p/842316#M333075</guid>
      <dc:creator>rinentert</dc:creator>
      <dc:date>2022-11-03T13:56:12Z</dc:date>
    </item>
  </channel>
</rss>

