<?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: filling missing values until new id in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807044#M25692</link>
    <description>&lt;P&gt;Then apply the technique shown for variable ID to the other variables as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input item1-item4 id $;
cards;
1 . . . xx2
. 0 . . .
. . 1 . .
. . . 1 .
0 . . . xx1
. 0 . . .
. . 1 . .
. . . 0 .
. . . . .
;

data _tmp(drop=_:) / view=_tmp;
set have(rename=(item1-item4=_i1-_i4 id=_id));
array item[4];
array _i[4];
if _id ne ' ' then id=_id;
do _j=1 to dim(_i);
  if _i[_j] ne . then item[_j]=_i[_j];
end;
retain item id;
run;

data want;
set _tmp;
by id notsorted;
if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on the structure of your real data, you can create dataset WANT in a single data step, but I don't want to make assumptions about your real data.&lt;/P&gt;</description>
    <pubDate>Sun, 10 Apr 2022 16:44:12 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-04-10T16:44:12Z</dc:date>
    <item>
      <title>filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807025#M25687</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a question: I have a data set as seen below. I used retain statement to create a data set as below in the second data set. However, it did not work for my case. I will appreciate for any suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 288pt;" border="0" width="384" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;have&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;number&lt;/TD&gt;
&lt;TD&gt;item1&lt;/TD&gt;
&lt;TD&gt;item2&lt;/TD&gt;
&lt;TD&gt;item3&lt;/TD&gt;
&lt;TD&gt;item4&lt;/TD&gt;
&lt;TD&gt;id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;xx1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;4&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;5&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;xx2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;6&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;7&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;8&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;9&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 288pt;" border="0" width="384" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;want&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;number&lt;/TD&gt;
&lt;TD&gt;item1&lt;/TD&gt;
&lt;TD&gt;item2&lt;/TD&gt;
&lt;TD&gt;item3&lt;/TD&gt;
&lt;TD&gt;item4&lt;/TD&gt;
&lt;TD&gt;id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;xx1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD&gt;xx2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 10 Apr 2022 13:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807025#M25687</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-04-10T13:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807034#M25688</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I used retain statement to create a data set as below in the second data set. However, it did not work for my case.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The issue with the RETAIN statement is that you would need to apply it to &lt;EM&gt;new&lt;/EM&gt; variables, not to those read by the SET statement. Variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;_id&lt;/FONT&gt; in the code below is an example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input item1-item4 id $;
cards;
1 . . . xx1
. 0 . . .
. . 1 . .
. . . 1 .
0 . . . xx2
. 0 . . .
. . 1 . .
. . . 0 .
. . . . .
;

data _tmp(drop=id rename=(_id=id)) / view=_tmp;
set have;
if id ne ' ' then _id=id;
retain _id;
run;

data want;
update _tmp(obs=0) _tmp;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Apr 2022 15:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807034#M25688</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-10T15:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807036#M25689</link>
      <description>&lt;P&gt;For each missing ID, you want to carry forward the previous non-missing id.&amp;nbsp; And you want to do the same for the ITEM variables.&amp;nbsp; I.e. you want the &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;last&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; non-missing value for each of these variables within an ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for the NUMBER variable, you want the &lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;first&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt; non-missing value for each ID group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Editted note:&amp;nbsp; Did I misread the OP posting?&amp;nbsp; I thought the second row of the desired output had NUMBER=5,&amp;nbsp; (not NUMBER=2 as I see now).&amp;nbsp; If so, then no special treatment is needed for NUMBER, like the SET ... POINT= statement below.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the ID column in dataset HAVE had no holes, and if HAVE were sorted by ID, then you could use a the UPDATE statement, with a SET .... POINT= statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  update have(obs=0) have (rename=(number=_number));
  by id;
  if first.id then number=_number;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't have that situation, but you could create a dataset NEED with all the missing ID values populated from the most recent non-missing ID value.&amp;nbsp; Then you could apply the UPDATE technique to NEED:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vneed (drop=_:) / view=vneed;
  set have (drop=number rename=(id=_test_id));
  if not missing(_test_id) then set have (keep=id number) point=_n_;
run;

data want;
  update vneed (obs=0) vneed;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 15:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807036#M25689</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-10T15:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807041#M25690</link>
      <description>Thank you for your answer. It says "by variables are not properly sorted on data set WORK._TMP"&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 10 Apr 2022 16:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807041#M25690</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-04-10T16:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807042#M25691</link>
      <description>Thank you for your answer. I am getting the same error. it says "by variables are not properly sorted on data set "&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 10 Apr 2022 16:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807042#M25691</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-04-10T16:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807044#M25692</link>
      <description>&lt;P&gt;Then apply the technique shown for variable ID to the other variables as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input item1-item4 id $;
cards;
1 . . . xx2
. 0 . . .
. . 1 . .
. . . 1 .
0 . . . xx1
. 0 . . .
. . 1 . .
. . . 0 .
. . . . .
;

data _tmp(drop=_:) / view=_tmp;
set have(rename=(item1-item4=_i1-_i4 id=_id));
array item[4];
array _i[4];
if _id ne ' ' then id=_id;
do _j=1 to dim(_i);
  if _i[_j] ne . then item[_j]=_i[_j];
end;
retain item id;
run;

data want;
set _tmp;
by id notsorted;
if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on the structure of your real data, you can create dataset WANT in a single data step, but I don't want to make assumptions about your real data.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2022 16:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807044#M25692</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-10T16:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807075#M25693</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your answer. I am getting the same error. it says "by variables are not properly sorted on data set "&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then sort the dataset NEED:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vneed (drop=_:) / view=vneed;
  set have (rename=(id=_test_id));
  if not missing(_test_id) then set have (keep=id) point=_n_;
run;
proc sort data=vneed out=need_sorted;
  by id;
run;
data want;
  update need_sorted (obs=0) need_sorted;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 00:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807075#M25693</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-11T00:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807077#M25694</link>
      <description>&lt;P&gt;Then make a variable for grouping that is sorted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile cards truncover ;
  input item1-item4 id $;
cards;
1 . . . xx1
. 0 . .
. . 1 .
. . . 1
0 . . . xx2
. 0 . .
. . 1 .
. . . 0
. . . .
;

data group ;
  set have;
  group+ not missing(id);
run;

data want;
  update group(obs=0) group;
  by group;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    item1    item2    item3    item4    id     group

 1       1        0        1        1      xx1      1
 2       0        0        1        0      xx2      2
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 01:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807077#M25694</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-11T01:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: filling missing values until new id</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807105#M25695</link>
      <description>&lt;P&gt;I didn't suggest a similar solution because of the&lt;SPAN&gt;&amp;nbsp;implied assumptions about the real data: It would fail if some of the IDs were repeated rather than missing (but could be modified to avoid this).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 07:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/filling-missing-values-until-new-id/m-p/807105#M25695</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-11T07:43:35Z</dc:date>
    </item>
  </channel>
</rss>

