<?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: do loop if /then statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780148#M248560</link>
    <description>&lt;P&gt;Figure out how to do ONE variable first.&amp;nbsp; To then apply the same logic to multiple variables there are two choices.&amp;nbsp; ) Use arrays and looping over the arrays to apply the same logic to multiple variables . 2) Transposing your data to actual TALL structure (not the intermediate structure you are starting with) and use the additional resulting variable as a BY variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you first want to calculate a change from baseline measure.&amp;nbsp; Then can try to access your criteria of sustained improvement to the end.&amp;nbsp; &amp;nbsp;Do you just want one number of each subject?&amp;nbsp; If so how would its result be different if you just took the change from baseline for the last visit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simple way to do a calculate change from baseline that will work if your data is sorted by subject and visit.&amp;nbsp; Say your identifier variable is named ID, your visit variable is named VISIT and your numeric variable is named VALUE.&amp;nbsp; First calculate a BASELINE value and then use the to compare to the following visit values to see if there is improvement.&amp;nbsp; SAS will evaluate a boolean expression as 1 for TRUE and 0 for FALSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by id visit;
  if first.id then baseline = value ;
  else improvement = (value&amp;gt;baseline) ;
  retain baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 14 Nov 2021 18:14:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-14T18:14:20Z</dc:date>
    <item>
      <title>x</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780041#M248494</link>
      <description />
      <pubDate>Mon, 15 Nov 2021 01:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780041#M248494</guid>
      <dc:creator>393310</dc:creator>
      <dc:date>2021-11-15T01:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780046#M248498</link>
      <description>&lt;P&gt;Your OUTPUT in the middle of the do loop forces SAS to write to the output data set for each iteration of the&amp;nbsp; K loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suggestion for readable code: do not place things like Array definitions or similar inside the loops. It makes it harder to follow the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Likely you want a structure like this if you want all the calculations in the K loop written once. Order of statements does matter.&lt;/P&gt;
&lt;PRE&gt;do i= 1 to limit;
   do k=1 to klimit;
    &amp;lt;stuff&amp;gt;
  end; /* k loop*/
  output;
end; /*i loop*/&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Nov 2021 21:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780046#M248498</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-12T21:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780051#M248501</link>
      <description>&lt;P&gt;Hi Thanks fo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 01:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780051#M248501</guid>
      <dc:creator>393310</dc:creator>
      <dc:date>2021-11-15T01:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780063#M248507</link>
      <description>&lt;P&gt;Here's a silly idea, provide a small example of data, maybe only 6 variables with about 5 rows of data.&lt;/P&gt;
&lt;P&gt;Show what you expect the output to look like. NOT as pictures:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is not place in your code where you assign a value to either Trouble_sleeping0 or Newvariables[1]. So I am not sure where you think 0, 1 come from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I submit that when you show a variable with values that match the NAME of a variable and then show a want of something completely different that you have the wrong assignment and possibly function&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 22:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780063#M248507</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-12T22:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780078#M248519</link>
      <description>&lt;P&gt;What is the question here?&lt;/P&gt;
&lt;P&gt;If sounds like you have instrument that is measuring multiple features (Anxiety, Depression, Trouble_Sleeping etc.) that you are getting result for multiple times.&amp;nbsp; How are the answers to those questions stored?&amp;nbsp; Are they numbers?&amp;nbsp; Perhaps something like "on a scale from 1 to 10 how Anxious have you been in the last week? with 1 being none and 10 by extremely"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to check for changes in each of the individual items?&amp;nbsp; For example increase in Anxiety?&lt;/P&gt;
&lt;P&gt;Perhaps something as simple as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id visit ;
  anxiety_change = sign( dif(anxiety) );
  if first.id then anxiety_change=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will result is values of ANXIETY_CHANGE on each observation of 0 (no change), 1 (increase), or -1 (decrease).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want something more complicated?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any need to convert the value on the multiple individual questions into a single scale?&amp;nbsp; If so what is the formula?&amp;nbsp; And do you want to asses the change in that aggregate scale over time also?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Nov 2021 01:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780078#M248519</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-13T01:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780119#M248544</link>
      <description>&lt;P&gt;I think that is on track for what I want. The variables are originally a numeric likert scale (anxiety is just 0 or 1) but the others in the data set are 0-5. At this point my data looks something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;record id&lt;/TD&gt;&lt;TD&gt;visit number&lt;/TD&gt;&lt;TD&gt;outcome(formatted values)&lt;/TD&gt;&lt;TD&gt;noformat(unformatted values of the outcomes)&lt;/TD&gt;&lt;TD&gt;N(number of times the same level of a variable was recorded)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Anxiety present&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Anxiety not present&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Anxiety not present&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a code that can compare the values between visit 1 and visit2-all visits. So I want to say if patient 1's noformat value was 0 at visits 2-allvisits (in this case 2-3) and noformat=1 at visit1 then X='improvement'. Basically to be categorized as improved the score has to improve and stay improved at all follow up visits. I am struggling because I don't know what the syntax would be for something like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do this with a long data set or do I have to transpose the data into a wide format?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 03:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780119#M248544</guid>
      <dc:creator>393310</dc:creator>
      <dc:date>2021-11-14T03:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: do loop if /then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/x/m-p/780148#M248560</link>
      <description>&lt;P&gt;Figure out how to do ONE variable first.&amp;nbsp; To then apply the same logic to multiple variables there are two choices.&amp;nbsp; ) Use arrays and looping over the arrays to apply the same logic to multiple variables . 2) Transposing your data to actual TALL structure (not the intermediate structure you are starting with) and use the additional resulting variable as a BY variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you first want to calculate a change from baseline measure.&amp;nbsp; Then can try to access your criteria of sustained improvement to the end.&amp;nbsp; &amp;nbsp;Do you just want one number of each subject?&amp;nbsp; If so how would its result be different if you just took the change from baseline for the last visit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simple way to do a calculate change from baseline that will work if your data is sorted by subject and visit.&amp;nbsp; Say your identifier variable is named ID, your visit variable is named VISIT and your numeric variable is named VALUE.&amp;nbsp; First calculate a BASELINE value and then use the to compare to the following visit values to see if there is improvement.&amp;nbsp; SAS will evaluate a boolean expression as 1 for TRUE and 0 for FALSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by id visit;
  if first.id then baseline = value ;
  else improvement = (value&amp;gt;baseline) ;
  retain baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Nov 2021 18:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/x/m-p/780148#M248560</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-14T18:14:20Z</dc:date>
    </item>
  </channel>
</rss>

