<?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: How to backfill missing values using the same table in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950722#M45517</link>
    <description>This is really interesting - almost like creating a name-to-customer ID lookup format and then applying it, but much more compact.  Almost 20 years of using SAS and I think I've used a hash table maybe twice.</description>
    <pubDate>Thu, 14 Nov 2024 02:53:18 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2024-11-14T02:53:18Z</dc:date>
    <item>
      <title>How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950393#M45501</link>
      <description>&lt;P&gt;Hi, is it possible to backfill the obs in row 1 , 2&amp;nbsp; and 7 with the customer_ID that became available in the later months?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scooby3g_0-1731363246229.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102085i99D69DDE74D49D3F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scooby3g_0-1731363246229.png" alt="Scooby3g_0-1731363246229.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	input customer_ID $ Na $ month $ cost;
	datalines;
	.	Joe	202401 100
	.	Joe	202402 150
	123 Joe	202403 200
	123	Joe	202404 250
	123 Joe	202405 300
	123 Joe	202406 375
	.	Jane 202401 100
	456 Jane 202402 175
	456 Jane 202403 200
	456 Jane 202404 275
	456 Jane 202405 300
	456 Jane 202406 375
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Nov 2024 22:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950393#M45501</guid>
      <dc:creator>Scooby3g</dc:creator>
      <dc:date>2024-11-11T22:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950405#M45502</link>
      <description>&lt;P&gt;That's logically only possible if for each name there is exactly one matching ID value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though "ugly" but because SAS tables are sequential it's also possible that your table is in a a sort order that we could always use the first non-blank ID for the same name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to tell us what's the case.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2024 23:07:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950405#M45502</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-11T23:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950412#M45503</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	input customer_ID $ Na $ month : yymmn6. cost;
	format month yymmn6.;
	datalines;
	.	Joe	202401 100
	.	Joe	202402 150
	123 Joe	202403 200
	123	Joe	202404 250
	123 Joe	202405 300
	123 Joe	202406 375
	.	Jane 202401 100
	456 Jane 202402 175
	456 Jane 202403 200
	456 Jane 202404 275
	456 Jane 202405 300
	456 Jane 202406 375
	;
run;
proc sort data=have out=temp;
by Na descending month;
run;
data want;
 length customer_ID $ 80;
 set temp(rename=(customer_ID=_customer_ID));
 by Na;
 retain customer_ID ;
 if first.Na then call missing(customer_ID);
 if not missing(_customer_ID) then customer_ID=_customer_ID;
 drop _customer_ID;
run;
proc sort data=want;by Na  month;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2024 00:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950412#M45503</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-12T00:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950413#M45504</link>
      <description>&lt;P&gt;If you have a big table,could try DOW skill:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	input customer_ID $ Na $ month : yymmn6. cost;
	format month yymmn6.;
	datalines;
	.	Joe	202401 100
	.	Joe	202402 150
	123 Joe	202403 200
	123	Joe	202404 250
	123 Joe	202405 300
	123 Joe	202406 375
	.	Jane 202401 100
	456 Jane 202402 175
	456 Jane 202403 200
	456 Jane 202404 275
	456 Jane 202405 300
	456 Jane 202406 375
	;
run;

data want;
if 0 then set have;
 do until(not missing(customer_ID) or last.Na);
  set have;
  by Na notsorted;
 end;
 _customer_ID=customer_ID;
 do until(not missing(customer_ID) or last.Na);
  set have;
  by Na notsorted;
  output;
 end;
drop customer_ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2024 01:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950413#M45504</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-12T01:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950484#M45505</link>
      <description>&lt;P&gt;No sorting is required.&amp;nbsp; If each name has at least one non-missing customer_id, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	input customer_ID $ Na $ month $ cost;
	datalines;
	.	Joe	202401 100
	.	Joe	202402 150
	123 Joe	202403 200
	123	Joe	202404 250
	123 Joe	202405 300
	123 Joe	202406 375
	.	Jane 202401 100
	456 Jane 202402 175
	456 Jane 202403 200
	456 Jane 202404 275
	456 Jane 202405 300
	456 Jane 202406 375
run;
data backfill/view=backfill;
  set have (keep=customer_id na where=(customer_id^=.));
  by na notsorted;
  if last.na;
run;

data want;
  set have (drop=customer_id);
  by na notsorted;
  if first.na then set backfill;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is two data steps, but only one retrieval of disk data, so should be very efficient.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2024 22:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950484#M45505</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-12T22:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950718#M45516</link>
      <description>&lt;P&gt;And here an approach using a hash table lookup.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  input customer_ID Na $ month : yymmn6. cost;
  format month yymmn6.;
  datalines;
. Joe 202401 100
. Joe 202402 150
123 Joe 202403 200
123 Joe 202404 250
123 Joe 202405 300
123 Joe 202406 375
. Jane 202401 100
456 Jane 202402 175
456 Jane 202403 200
456 Jane 202404 275
456 Jane 202405 300
456 Jane 202406 375
;
run;

data want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(not missing(customer_id)))');
      h1.defineKey('na');
      h1.defineData('customer_id');
      h1.defineDone();
    end;
  set have;
  if missing(customer_id) then h1.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 01:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950718#M45516</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-14T01:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950722#M45517</link>
      <description>This is really interesting - almost like creating a name-to-customer ID lookup format and then applying it, but much more compact.  Almost 20 years of using SAS and I think I've used a hash table maybe twice.</description>
      <pubDate>Thu, 14 Nov 2024 02:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950722#M45517</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-11-14T02:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to backfill missing values using the same table</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950863#M45523</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223320"&gt;@quickbluefish&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's very worthwhile getting up-to-speed with hash tables.&amp;nbsp;Like with formats hash table lookups can be very efficient because they don't require sorting of the main table. Unlike with formats you can have a composite key and lookup multiple variables. You can also load multiple rows (items) per key and then iterate over them using the do_over() method.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 23:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-backfill-missing-values-using-the-same-table/m-p/950863#M45523</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-14T23:19:58Z</dc:date>
    </item>
  </channel>
</rss>

