<?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: Calculating Difference Scores in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636977#M78136</link>
    <description>&lt;P&gt;From values in the data set how do we determine which value is the "value for Stimulation at time 0 from the alcohol session" and "Stimulation at time 0 from the placebo session" (not order in a picture but a rule, set of variable values or similar)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not have any variable labeled "time" so this is somewhat important.&lt;/P&gt;
&lt;P&gt;How do we identify "participant"? What role does drinking_session play? (I suspect that this has some correspondence to time 0 but you didn't tell us that).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is what does the desired output look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is some pseudo code that places a difference on what I think is the row with the placebo value.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   retain alc ;
   by study_id drinking_session;
   if first.study_id then alc=youralcoholvariable;
   if first.drinking_session and drinking_session=2 
      then difference = alc -yourplacebovariable;
run;
&lt;/PRE&gt;
&lt;P&gt;This assumes the data is sorted by study_id drinking_session and that the orders of the variables of interest appear on the first record the drinking session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It has been a long time since I did anything with SPSS and do not remember an equivalent to the SAS First and Last processing. Good luck.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Apr 2020 17:36:47 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-02T17:36:47Z</dc:date>
    <item>
      <title>Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636927#M78131</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I got asked what I thought was a relatively easy question today, but after getting into it, I couldn't answer it on my own. I am turning to you all as I am sure that someone else has dealt with something similar. I am trying to create difference scores, but all I have to go off of is a screenshot of an SPSS dataset as they say they can't share the whole set with me. I do recognize that I am in a SAS forum, but it's mostly about the logic behind the problem. I also recognize that we do not generally like pictures but rather the data itself. Again, I apologize but am working with what I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have edited the picture for clarity.&amp;nbsp;&lt;SPAN&gt;I'm trying to create a new variable that takes a participant's value for Stimulation at time 0 from the alcohol session minus the value for Stimulation at time 0 from the placebo session (i.e., AmPstim; Alcohol minus Placebo for stimulation; two cells highlighted red in picture above). However, because each value is on a different row it won't let me create a difference score. My suggestion was to switch to wide format to create the difference score and then switch back, but I was wondering if anyone knew a way to do this with syntax while keeping it in long format(SPSS would be preferred but I can pretty easily translate SAS to SPSS). Alternatively, I would love any lessons on how others would proceed with this type of problem in the future or any applications of why one way would be better as I cannot wrap my head around the logic to program is.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Thank you in advance and I apologize for not adhering to all of the rules.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SPSS_EDGE.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37683iF836DEC75BCD189A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SPSS_EDGE.png" alt="SPSS_EDGE.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636927#M78131</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T16:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636931#M78132</link>
      <description>By "know of a way to do this with syntax", I simply mean "to keep it in long format and still do the same thing". I find the logic quite tricky but it seems like a complex If-Then or a "when" statement. I default to you experts.&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636931#M78132</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T16:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636938#M78133</link>
      <description>&lt;P&gt;I may be missing it in your message, but what do you want as output?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636938#M78133</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-02T16:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636940#M78134</link>
      <description>The difference score of Astimulation_tot (when order= alcohol) - Pstimulation_tot (when order= placebo) for each of the assessment_r that they share for each participant.&lt;BR /&gt;&lt;BR /&gt;I hope that clarifies it a bit more.</description>
      <pubDate>Thu, 02 Apr 2020 16:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636940#M78134</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T16:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636974#M78135</link>
      <description>&lt;P&gt;Where would that go in the screenshot?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636974#M78135</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-02T17:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636977#M78136</link>
      <description>&lt;P&gt;From values in the data set how do we determine which value is the "value for Stimulation at time 0 from the alcohol session" and "Stimulation at time 0 from the placebo session" (not order in a picture but a rule, set of variable values or similar)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not have any variable labeled "time" so this is somewhat important.&lt;/P&gt;
&lt;P&gt;How do we identify "participant"? What role does drinking_session play? (I suspect that this has some correspondence to time 0 but you didn't tell us that).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is what does the desired output look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is some pseudo code that places a difference on what I think is the row with the placebo value.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   retain alc ;
   by study_id drinking_session;
   if first.study_id then alc=youralcoholvariable;
   if first.drinking_session and drinking_session=2 
      then difference = alc -yourplacebovariable;
run;
&lt;/PRE&gt;
&lt;P&gt;This assumes the data is sorted by study_id drinking_session and that the orders of the variables of interest appear on the first record the drinking session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It has been a long time since I did anything with SPSS and do not remember an equivalent to the SAS First and Last processing. Good luck.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636977#M78136</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-02T17:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636981#M78137</link>
      <description>It would be a new variable called "AmPStim".</description>
      <pubDate>Thu, 02 Apr 2020 17:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636981#M78137</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T17:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636982#M78138</link>
      <description>&lt;P&gt;In SAS I would merge the data with itself, rather than make it a single row and then do the subtraction. You can do the similar functionality in SPSS by merging, doing the subtraction/create a new variable and only keeping the results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636982#M78138</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-02T17:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636983#M78139</link>
      <description>Can you explain what "merge the data with itself" means? I am not familiar with that concept. I was under the impression you could only merge two (or more) different datasets.</description>
      <pubDate>Thu, 02 Apr 2020 17:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636983#M78139</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T17:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Difference Scores</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636987#M78140</link>
      <description>&lt;P&gt;I apologize. I was evidently not very clear judging by the confusion regarding this. Still, thank you for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To answer some of your questions in case someone else comes along and wants this valuable information,&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;From values in the data set how do we determine which value is the "value for Stimulation at time 0 from the alcohol session" and "Stimulation at time 0 from the placebo session" (not order in a picture but a rule, set of variable values or similar)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;These should be the variables highlighted in the red boxes. The output that I desire is &lt;SPAN&gt;&amp;nbsp;Astimulation_tot (when order= alcohol) - Pstimulation_tot (when order= placebo) for each of the assessment_r that they share for each participant.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;P&gt;You do not have any variable labeled "time" so this is somewhat important.&lt;/P&gt;&lt;P&gt;How do we identify "participant"? What role does drinking_session play? (I suspect that this has some correspondence to time 0 but you didn't tell us that).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That was one of the comments I had as well is that "time" is really important here. I believe the "time" variable to be "assessment_r" as it ranges from 0 to 11 and repeats this pattern when order=placebo and order=alcohol.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The participant is based on the "study_id" which is unique for each participant. Drinking_session is only ever 1 or 2. Some participants did alcohol first and some did placebo. Again, this is how I interpreted it as I got roughly the same description you got, but I do have the ability to ask him some questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;P&gt;Second is what does the desired output look like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is some pseudo code that places a difference on what I think is the row with the placebo value.&lt;/P&gt;&lt;PRE&gt;data want;
   set have;
   retain alc ;
   by study_id drinking_session;
   if first.study_id then alc=youralcoholvariable;
   if first.drinking_session and drinking_session=2 
      then difference = alc -yourplacebovariable;
run;&lt;/PRE&gt;&lt;P&gt;This assumes the data is sorted by study_id drinking_session and that the orders of the variables of interest appear on the first record the drinking session.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It has been a long time since I did anything with SPSS and do not remember an equivalent to the SAS First and Last processing. Good luck.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The desired output&lt;SPAN&gt;&amp;nbsp;would be a new variable called "AmPStim" that would be the difference scores explained above. For instance, the first few would be 8-0 = &lt;STRONG&gt;8&lt;/STRONG&gt;; 54 - 3 = &lt;STRONG&gt;51&lt;/STRONG&gt;; 36-2= &lt;STRONG&gt;34;&amp;nbsp;&lt;/STRONG&gt;22-0=&amp;nbsp;&lt;STRONG&gt;22.&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The data is sorted by study_id.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I appreciate you taking the time to write all this out for me! I can look up the first and last processing for SPSS as it has been a while for me as well.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Apr 2020 17:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-Difference-Scores/m-p/636987#M78140</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-04-02T17:54:51Z</dc:date>
    </item>
  </channel>
</rss>

