<?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: Add additional row for specific patient IDs after last recorded month in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466362#M14561</link>
    <description>&lt;P&gt;Paste test data as text, e.g.:&lt;/P&gt;
&lt;PRE&gt;data have; 
  input...
datalines;
...
;
run;&lt;/PRE&gt;
&lt;P&gt;You can attach files (make sure the extension matches, so you said it was a .sas file which is text, but talk about a datafile, which is sas7bdat).&amp;nbsp; However I would always advise to post as text, most will not download files from the internet.&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 08:55:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-05-31T08:55:05Z</dc:date>
    <item>
      <title>Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/465988#M14521</link>
      <description>&lt;P&gt;Hi There,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with many rows per patient ID, whereby each row represents a month of follow up in a cohort study. To run a weighted regression model I need to add an extra month after the last month of follow up for all patients with CENS_REASON='changeexp' or 'switch'. In this additional row the outcome should be set to missing (.) and exposure becomes 0 in case of 'changeexp' and the alternate of the prior number for 'switch' i.e. 1 becomes 2 and 2 becomes 1, month becomes ('last month'+1) and PatID should be carried down - all other covariates can be missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The file has many more covariates and varying lab values over time in several thousand observations so I need to do that automated somehow,&amp;nbsp; but I don't know how to go about it (consequently I haven't tried anything yet). Any help is appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My file has the following structure (many other covariates that are not listed too):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PatID&amp;nbsp; &amp;nbsp;exposure&amp;nbsp; &amp;nbsp;month&amp;nbsp; &amp;nbsp; cens_reason&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;outcome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I need it to have the following structure&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PatID&amp;nbsp; &amp;nbsp;exposure&amp;nbsp; &amp;nbsp;month&amp;nbsp; &amp;nbsp; cens_reason&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;outcome&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;death&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;changeexp&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 12:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/465988#M14521</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-30T12:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466002#M14522</link>
      <description>&lt;P&gt;Not here to type that test data in, post test data in the form of a datastep, as such this is just a guide:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  by cens_reason;
  if last.cens_reason and cens_reason in ('switch','changeexp') then do;
    output;
    month=month+1;
    output;    
  end;
  else output;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 May 2018 13:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466002#M14522</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-30T13:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466046#M14523</link>
      <description>&lt;P&gt;Thank you so much that worked perfectly! I just slightly changed it to:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp.marginal2;
  set temp.marginal1;
  by USRDS_ID month;
  if last.USRDS_ID and at_death_reason in ('switch','changeexp') then do;
    output;
    month=month+1;    
	outcome=.;
	output; 
  end;
  else output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wasn't sure how to create a sample data set if I dont work with the SAS University Edition - any link for instructions for next time?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 14:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466046#M14523</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-30T14:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466049#M14524</link>
      <description>&lt;P&gt;Please provide data in the form of datastep &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="_self"&gt;check here how&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like your 9th records must have patid 3 instead of 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input PatID   exposure   month    cens_reason   :$15.      outcome;
datalines;
1 2 0 switch 0
1 2 1 switch 0
1 2 2 switch 0
2 1 0 death 0
2 1 1 death 0
2 1 2 death 1
3 2 0 changeexp 0
3 2 1 changeexp 0
3 2 2 changeexp 0
3 2 3 changeexp 0
;
run;

proc sort data=have;
by PatID exposure month cens_reason;
run;

data want ;
set have;
by PatID;
if last.patid and cens_reason in ("changeexp","switch") then do;
output;
month=month+1;
if cens_reason="switch" then exposure=exposure-1;
else exposure=0;
call missing(cens_reason,outcome);
output;
end;
else output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 May 2018 14:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466049#M14524</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-30T14:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466052#M14525</link>
      <description>&lt;P&gt;You can use this in any SAS software:&lt;/P&gt;
&lt;P&gt;&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;&lt;/P&gt;</description>
      <pubDate>Wed, 30 May 2018 14:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466052#M14525</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-30T14:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466337#M14552</link>
      <description>&lt;P&gt;Great, thank you for the link! Will test right now&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 07:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466337#M14552</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-31T07:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466354#M14558</link>
      <description>&lt;P&gt;You are right - thanks for pointing this out. I did manage to create a test data set with the macro from the link - thanks will use that for future posts! However, I&amp;nbsp;&amp;nbsp;tried to attach the file (test.sas) via the 'choose files' button but it wont let me upload it but I get the error message saying 'the contents of the attachment doesn't match its file type' - any recommendations on what I am doing wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code however worked perfectly -so no need to look into it for now. Thanks so much for the quick help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466354#M14558</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-31T08:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466357#M14559</link>
      <description>&lt;P&gt;Best way is to copy + paste the text and post it in a code window.&amp;nbsp; The code window is opened by using the {i} above the post area - this retains code formatting and such like.&amp;nbsp; Note we only need a few rows of test data just to show structure and some example of the data.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466357#M14559</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T08:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466360#M14560</link>
      <description>&lt;P&gt;I get that for the code, but if I want to attach a dataset I will need to do it differently no? I ran the macro to create some test data for my question - but I cant attach it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466360#M14560</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-31T08:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466362#M14561</link>
      <description>&lt;P&gt;Paste test data as text, e.g.:&lt;/P&gt;
&lt;PRE&gt;data have; 
  input...
datalines;
...
;
run;&lt;/PRE&gt;
&lt;P&gt;You can attach files (make sure the extension matches, so you said it was a .sas file which is text, but talk about a datafile, which is sas7bdat).&amp;nbsp; However I would always advise to post as text, most will not download files from the internet.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466362#M14561</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-31T08:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add additional row for specific patient IDs after last recorded month</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466363#M14562</link>
      <description>&lt;P&gt;Ok great, will do next time - thank!&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 08:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Add-additional-row-for-specific-patient-IDs-after-last-recorded/m-p/466363#M14562</guid>
      <dc:creator>js1983</dc:creator>
      <dc:date>2018-05-31T08:56:48Z</dc:date>
    </item>
  </channel>
</rss>

