<?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 How to shift rows up in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-shift-rows-up/m-p/732075#M28470</link>
    <description>&lt;P&gt;Hello Community,&lt;/P&gt;
&lt;P&gt;I have a following example table:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iced_tea_1-1617825349036.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57099iACB484B6AD8410CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iced_tea_1-1617825349036.png" alt="iced_tea_1-1617825349036.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use this dataset to create a new one, where Obs 3 and 4 are combined and output on the same row because they were on the same date, and Obs 6 and 7 are on the same row because again, they were on the same date.&lt;/P&gt;
&lt;PRE&gt;/*Example of initial dataset.*/&lt;BR /&gt;data example;&lt;BR /&gt;input employee_id $ date :DATE8. AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;format date DATE8.;&lt;BR /&gt;format AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;9781 29MAR20 1 . .&lt;BR /&gt;9781 09APR20 . . 1&lt;BR /&gt;9781 21JUN20 1 . .&lt;BR /&gt;9781 21JUN20 . . 1&lt;BR /&gt;9781 26JUN20 . . 1&lt;BR /&gt;1234 12MAR19 . . 1&lt;BR /&gt;1234 12MAR19 . 1 .&lt;BR /&gt;1234 15MAR19 1 . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=example;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*Example of eventual dataset.*/&lt;BR /&gt;data want;&lt;BR /&gt;input employee_id $ date :DATE8. AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;format date DATE8.;&lt;BR /&gt;format AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;9781 29MAR20 1 . .&lt;BR /&gt;9781 09APR20 . . 1&lt;BR /&gt;9781 21JUN20 1 . 1&lt;BR /&gt;9781 26JUN20 . . 1&lt;BR /&gt;1234 12MAR19 . 1 1&lt;BR /&gt;1234 15MAR19 1 . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=want;&lt;BR /&gt;run;&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Apr 2021 19:58:05 GMT</pubDate>
    <dc:creator>iced_tea</dc:creator>
    <dc:date>2021-04-07T19:58:05Z</dc:date>
    <item>
      <title>How to shift rows up</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-shift-rows-up/m-p/732075#M28470</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;
&lt;P&gt;I have a following example table:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iced_tea_1-1617825349036.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57099iACB484B6AD8410CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iced_tea_1-1617825349036.png" alt="iced_tea_1-1617825349036.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use this dataset to create a new one, where Obs 3 and 4 are combined and output on the same row because they were on the same date, and Obs 6 and 7 are on the same row because again, they were on the same date.&lt;/P&gt;
&lt;PRE&gt;/*Example of initial dataset.*/&lt;BR /&gt;data example;&lt;BR /&gt;input employee_id $ date :DATE8. AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;format date DATE8.;&lt;BR /&gt;format AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;9781 29MAR20 1 . .&lt;BR /&gt;9781 09APR20 . . 1&lt;BR /&gt;9781 21JUN20 1 . .&lt;BR /&gt;9781 21JUN20 . . 1&lt;BR /&gt;9781 26JUN20 . . 1&lt;BR /&gt;1234 12MAR19 . . 1&lt;BR /&gt;1234 12MAR19 . 1 .&lt;BR /&gt;1234 15MAR19 1 . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=example;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*Example of eventual dataset.*/&lt;BR /&gt;data want;&lt;BR /&gt;input employee_id $ date :DATE8. AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;format date DATE8.;&lt;BR /&gt;format AdvancedCourse IntermediaryCourse BeginnerCourse 8.;&lt;BR /&gt;datalines;&lt;BR /&gt;9781 29MAR20 1 . .&lt;BR /&gt;9781 09APR20 . . 1&lt;BR /&gt;9781 21JUN20 1 . 1&lt;BR /&gt;9781 26JUN20 . . 1&lt;BR /&gt;1234 12MAR19 . 1 1&lt;BR /&gt;1234 15MAR19 1 . .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=want;&lt;BR /&gt;run;&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 19:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-shift-rows-up/m-p/732075#M28470</guid>
      <dc:creator>iced_tea</dc:creator>
      <dc:date>2021-04-07T19:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to shift rows up</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-shift-rows-up/m-p/732084#M28471</link>
      <description>&lt;P&gt;If (1) you are ok with re-ordered the data by employee_id/date, and (2) you want to keep the latest non-missing values for each employee_id/date, then UPDATE does what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input employee_id $ date :DATE8. AdvancedCourse IntermediaryCourse BeginnerCourse 8.;
format date DATE9.;
format AdvancedCourse IntermediaryCourse BeginnerCourse 8.;
datalines;
9781 29MAR20 1 . .
9781 09APR20 . . 1
9781 21JUN20 1 . .
9781 21JUN20 . . 1
9781 26JUN20 . . 1
1234 12MAR19 . . 1
1234 12MAR19 . 1 .
1234 15MAR19 1 . .
;
run;

proc sort data=example out=need equals;
  by employee_id date;
run;
data want;
  update need (obs=0) need;
  by employee_id date;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "equals" keeps all ties in the sort keys in original order, although that shouldn't be a problem here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Think of the UPDATE statement as updating a masterfile with transactions - except the only transactions that are recorded are the non-missing values - no transaction can modify a variable from non-missing to missing.&amp;nbsp; I use the "obs=0" in the left side of the update statement, because the initial "master" file (the first NEED in the update statement has multiple records per byvars, but we only want one such record in the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike the above, UPDATE was originally intended for such separate master and transaction data sets, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newmaster;
  update master   transgrp1 ;
  by unique_id;
urn;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 20:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-shift-rows-up/m-p/732084#M28471</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-07T20:32:26Z</dc:date>
    </item>
  </channel>
</rss>

