<?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 Creating one observation per subject between the first and last visit. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592870#M170052</link>
    <description>&lt;P&gt;Is there any information on how to create one observation per subject between the first and last visit in SAS data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 00:12:18 GMT</pubDate>
    <dc:creator>michelle05</dc:creator>
    <dc:date>2019-10-01T00:12:18Z</dc:date>
    <item>
      <title>Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592870#M170052</link>
      <description>&lt;P&gt;Is there any information on how to create one observation per subject between the first and last visit in SAS data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592870#M170052</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T00:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592874#M170054</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290387"&gt;@michelle05&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there any information on how to create one observation per subject between the first and last visit in SAS data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Much more information is needed. Specifically, we need to see a portion of your data AND an example of the desired output from this sample data.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592874#M170054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-01T00:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592877#M170055</link>
      <description>&lt;P&gt;So I am to create a new data set (CHANGE) with one observation per subject with the difference in WEIGHT between the first and last visit.&amp;nbsp; I am also to include in this data set the number of days between the first and last visit.&amp;nbsp; Do not include any patients who have only one visit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have done so far.&lt;/P&gt;&lt;PRE&gt;DATA CLINICAL;&lt;BR /&gt;*Use LENGTH statement to control the order of &lt;BR /&gt;variables in the data set;&lt;BR /&gt;LENGTH PATIENT VISIT DATE_VISIT 8;&lt;BR /&gt;RETAIN DATE_VISIT WEIGHT;&lt;BR /&gt;DO PATIENT = 1 TO 25;&lt;BR /&gt;IF RANUNI(135) LT .5 THEN GENDER = 'FEMALE';&lt;BR /&gt;ELSE GENDER = 'MALE';&lt;BR /&gt;X = RANUNI (135);&lt;BR /&gt;IF X LT .33 THEN GROUP = 'A';&lt;BR /&gt;ELSE IF X LT .66 THEN GROUP = 'B';&lt;BR /&gt;ELSE GROUP = 'C';&lt;BR /&gt;DO VISIT = 1 TO INT (RANUNI(135)*5);&lt;BR /&gt;IF VISIT = 1 THEN DO;&lt;BR /&gt;DATE_VISIT = INT(RANUNI(135)*100)+15800;&lt;BR /&gt;WEIGHT = INT(RANNOR(135)*10 + 150);&lt;BR /&gt;END;&lt;BR /&gt;ELSE DO;&lt;BR /&gt;DATE_VISIT = DATE_VISIT + VISIT*(10 + INT(RANUNI(135)*50));&lt;BR /&gt;WEIGHT= WEIGHT + INT(RANNOR(135)*10);&lt;BR /&gt;END;&lt;BR /&gt;OUTPUT;&lt;BR /&gt;IF RANUNI(135) LT .2 THEN LEAVE;&lt;BR /&gt;END;&lt;BR /&gt;END;&lt;BR /&gt;DROP X;&lt;BR /&gt;FORMAT DATE_VISIT DATE9.;&lt;BR /&gt;RUN;&lt;BR /&gt;*Assume data set Clinical is already sorted by VISIT and DATE;&lt;BR /&gt;DATA DIFFERENCE;&lt;BR /&gt;SET CLINICAL;&lt;BR /&gt;LENGTH;&lt;BR /&gt;DIFF_WEIGHT= WEIGHT-LAG(WEIGHT);&lt;BR /&gt;IF NOT FIRST.VISIT THEN OUTPUT;&lt;BR /&gt;PROC PRINT DATA=DIFFERENCE;&lt;BR /&gt;RUN;&lt;BR /&gt;DATA CHANGE;&lt;BR /&gt;SET CLINICAL;&lt;BR /&gt;DIFF_WEIGHT=WEIGHT-LAG(WEIGHT);&lt;BR /&gt;***OMIT PATIENT WITH ONLY ONE VISIT;&lt;BR /&gt;IF FIRST.VISIT AND LAST.VISIT THEN DELETE;&lt;BR /&gt;***IF IT IS THE FIRST VISIT ASSIGN VALUES TO THE&lt;BR /&gt;RETAINED VARIABLES;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592877#M170055</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T00:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592878#M170056</link>
      <description>&lt;P&gt;We need to see a portion of your data AND an example of the desired output from this sample data.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592878#M170056</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-01T00:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592879#M170057</link>
      <description>&lt;P&gt;Are you asking about after I run the code?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592879#M170057</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T00:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592880#M170058</link>
      <description>&lt;P&gt;This is the portion that I entered in.&lt;/P&gt;
&lt;PRE&gt;*Assume data set Clinical is already sorted by VISIT and DATE;&lt;BR /&gt;DATA DIFFERENCE;&lt;BR /&gt;SET CLINICAL;&lt;BR /&gt;LENGTH;&lt;BR /&gt;DIFF_WEIGHT= WEIGHT-LAG(WEIGHT);&lt;BR /&gt;IF NOT FIRST.VISIT THEN OUTPUT;&lt;BR /&gt;PROC PRINT DATA=DIFFERENCE;&lt;BR /&gt;RUN;&lt;BR /&gt;DATA CHANGE;&lt;BR /&gt;SET CLINICAL;&lt;BR /&gt;DIFF_WEIGHT=WEIGHT-LAG(WEIGHT);&lt;BR /&gt;***OMIT PATIENT WITH ONLY ONE VISIT;&lt;BR /&gt;IF FIRST.VISIT AND LAST.VISIT THEN DELETE;&lt;BR /&gt;***IF IT IS THE FIRST VISIT ASSIGN VALUES TO THE&lt;BR /&gt;RETAINED VARIABLES;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 00:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592880#M170058</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T00:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592882#M170060</link>
      <description>&lt;DIV id="sasLogNote1_1569891737901" class="sasNote"&gt;NOTE: The data set WORK.CLINICAL has 49 observations and 6 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1569891737901" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;user cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;system cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;memory 703.00k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;OS Memory 28840.00k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Timestamp 10/01/2019 01:02:18 AM&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Step Count 59 Switch Count 2&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Faults 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Reclaims 164&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Swaps 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Voluntary Context Switches 10&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Involuntary Context Switches 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Input Operations 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Output Operations 264&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;99 *Assume data set Clinical is already sorted by VISIT and DATE;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;100 DATA DIFFERENCE;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;101 SET CLINICAL;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;102 LENGTH;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;103 DIFF_WEIGHT= WEIGHT-LAG(WEIGHT);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;104 IF NOT FIRST.VISIT THEN OUTPUT;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1569891737901" class="sasNote"&gt;NOTE: Variable 'FIRST.VISIT'n is uninitialized.&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1569891737901" class="sasNote"&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;1 at 103:20&lt;/DIV&gt;
&lt;DIV id="sasLogNote5_1569891737901" class="sasNote"&gt;NOTE: There were 49 observations read from the data set WORK.CLINICAL.&lt;/DIV&gt;
&lt;DIV id="sasLogNote6_1569891737901" class="sasNote"&gt;NOTE: The data set WORK.DIFFERENCE has 49 observations and 7 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote7_1569891737901" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;user cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;system cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;memory 949.28k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;OS Memory 29100.00k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Timestamp 10/01/2019 01:02:18 AM&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Step Count 60 Switch Count 2&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Faults 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Reclaims 129&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Swaps 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Voluntary Context Switches 11&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Involuntary Context Switches 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Input Operations 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Output Operations 264&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;105 PROC PRINT DATA=DIFFERENCE;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;106 RUN;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote8_1569891737901" class="sasNote"&gt;NOTE: There were 49 observations read from the data set WORK.DIFFERENCE.&lt;/DIV&gt;
&lt;DIV id="sasLogNote9_1569891737901" class="sasNote"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.09 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;user cpu time 0.09 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;system cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;memory 2329.18k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;OS Memory 29864.00k&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Timestamp 10/01/2019 01:02:18 AM&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Step Count 61 Switch Count 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Faults 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Reclaims 211&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Page Swaps 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Voluntary Context Switches 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Involuntary Context Switches 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Input Operations 0&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;Block Output Operations 32&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;107 DATA CHANGE;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;108 SET CLINICAL;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;109 DIFF_WEIGHT=WEIGHT-LAG(WEIGHT);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;110 ***OMIT PATIENT WITH ONLY ONE VISIT;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;111 IF FIRST.VISIT AND LAST.VISIT THEN DELETE;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;112 ***IF IT IS THE FIRST VISIT ASSIGN VALUES TO THE&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;113 RETAINED VARIABLES;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;114&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;115&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;116&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;117 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;128&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Oct 2019 01:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592882#M170060</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T01:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592889#M170063</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290387"&gt;@michelle05&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's really hard to know what's not working if we don't see the data. Ideally provide sample data in form of a SAS data step and then show us how the desired result should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking into your code you've got the following Note:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE: Variable 'FIRST.VISIT'n is uninitialized.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What this means: You forgot to add a BY VISIT DATE; to your data step. For this reason your IF FIRST.VISIT logic is not going to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also: Please do me the favour and end a SAS Data Step with a RUN; statement;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below the code you've posted with the BY and RUN statements added.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Assume data set Clinical is already sorted by VISIT and DATE;
DATA DIFFERENCE;
  SET CLINICAL;
  by visit date;
  LENGTH;
  DIFF_WEIGHT= WEIGHT-LAG(WEIGHT);

  IF NOT FIRST.VISIT THEN
    OUTPUT;
run;

PROC PRINT DATA=DIFFERENCE;
RUN;

DATA CHANGE;
  SET CLINICAL;
  by visit date;
  DIFF_WEIGHT=WEIGHT-LAG(WEIGHT);

  ***OMIT PATIENT WITH ONLY ONE VISIT;
  IF FIRST.VISIT AND LAST.VISIT THEN
    DELETE;

  ***IF IT IS THE FIRST VISIT ASSIGN VALUES TO THE
  RETAINED VARIABLES;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 01:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592889#M170063</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-01T01:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating one observation per subject between the first and last visit.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592890#M170064</link>
      <description>&lt;P&gt;Yes sir!&amp;nbsp; I promise I am trying my best to learn the language and programming.&amp;nbsp; I get myself confused to the point where I'm always confused and doubting myself.&amp;nbsp; Thank you for the information.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 02:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-one-observation-per-subject-between-the-first-and-last/m-p/592890#M170064</guid>
      <dc:creator>michelle05</dc:creator>
      <dc:date>2019-10-01T02:22:20Z</dc:date>
    </item>
  </channel>
</rss>

