<?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 merge so that the ID variable begins to repeat in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884842#M20815</link>
    <description>&lt;P&gt;To fill in the missing day*hour just take the distinct values of ID and make a skeleton dataset with just those three variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know the 7 days?&lt;/P&gt;
&lt;P&gt;Do you want 24 hours per day?&amp;nbsp; From 0 to 23?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  set have (keep=id);
  by id;
  if first.id;
  do date=&amp;amp;date1 to &amp;amp;date2 ;
    do hour=0 to 23 ;
      output;
    end;
  end;
run;

data want;
   merge all have ;
   by id date hour ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What values do you want for the OTHER variables on those new observations?&lt;/P&gt;
&lt;P&gt;This example will leave them as MISSING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2023 17:42:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-14T17:42:11Z</dc:date>
    <item>
      <title>How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884840#M20814</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am at my witts end trying to figure this out. I have a dataset that Has ID Hour Date. If the data I receive does not have each hour (0-23) I need to add it for the ID and Date. If the Date is Missing I also need to add the Date along with the Hour. The Date is on a 7 day block and I run this report once a week.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I have to this point:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data = want;&lt;BR /&gt;by ID Hours DATE;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc means data = want noprint;&lt;BR /&gt;by ID Hours DATE;&lt;BR /&gt;var Minutes_Since_Previous_Scan;&lt;BR /&gt;output out= Look;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = Look;&lt;BR /&gt;by ID Hours Date;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=Look out=Transpose;&lt;BR /&gt;by ID Hours Date;&lt;BR /&gt;id _STAT_;&lt;BR /&gt;var Minutes_Since_Previous_Scan;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data = transpose;&lt;BR /&gt;by Date Hours;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = Insert;&lt;BR /&gt;by Date Hours;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data merger;&lt;BR /&gt;merge insert transpose ;&lt;BR /&gt;by Date Hours;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem with this code is it will only insert the hour and date onto the first IDI have to this point. I need it to continue to look at all IDs in the set and continue to add the hour for each date if it is not present. I have made a sheet that would read it but to update the IDs every week only hundreds of IDs is too cumbersome. Any help is appreciated. Thanks,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884840#M20814</guid>
      <dc:creator>Mercadja</dc:creator>
      <dc:date>2023-07-14T17:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884842#M20815</link>
      <description>&lt;P&gt;To fill in the missing day*hour just take the distinct values of ID and make a skeleton dataset with just those three variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know the 7 days?&lt;/P&gt;
&lt;P&gt;Do you want 24 hours per day?&amp;nbsp; From 0 to 23?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  set have (keep=id);
  by id;
  if first.id;
  do date=&amp;amp;date1 to &amp;amp;date2 ;
    do hour=0 to 23 ;
      output;
    end;
  end;
run;

data want;
   merge all have ;
   by id date hour ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What values do you want for the OTHER variables on those new observations?&lt;/P&gt;
&lt;P&gt;This example will leave them as MISSING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884842#M20815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T17:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884843#M20816</link>
      <description>&lt;P&gt;Thank you for the reply. It is the 7 days of the week based on the report that I am working for. I created an excel file with the dates and the Hours for each date but I do not have the by variable of ID. Is the code you sent still applicable of does it need adjustment with this new information?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884843#M20816</guid>
      <dc:creator>Mercadja</dc:creator>
      <dc:date>2023-07-14T17:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884844#M20817</link>
      <description>Do you have SAS ETS?  For your 7 day period is it relative to the data, when does it start/end?</description>
      <pubDate>Fri, 14 Jul 2023 17:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884844#M20817</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-14T17:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884845#M20818</link>
      <description>&lt;P&gt;An EXCEL file is not much value, but if you convert it to an actual dataset with DAY and HOUR variables then you can make the skeleton dataset very easily with an SQL cross join query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the set of ID values is in HAVE and the set of DAY*HOUR combinations is in DAYS then the to make the ALL dataset just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table all as
  select distinct a.id,b.day,b.hour
  from have a 
     , days b
  order by 1,2,3
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884845#M20818</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-14T17:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884846#M20819</link>
      <description>I think you may have two problems here, one is merging in summary stats and one is expanding missing information. Can you provide a small sample of your data to illustrate the issue? Fake data is fine. You don't need Excel in the process, SAS can definitely handle this automatically. &lt;BR /&gt;&lt;BR /&gt;I'm not sure how the proc means is incorporated into the problem, which is why the sample data will ensure you get a working solution.</description>
      <pubDate>Fri, 14 Jul 2023 17:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884846#M20819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-14T17:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884847#M20820</link>
      <description>&lt;P&gt;I could kiss you TOM!! Thanks a ton this is exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2023 17:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884847#M20820</guid>
      <dc:creator>Mercadja</dc:creator>
      <dc:date>2023-07-14T17:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to merge so that the ID variable begins to repeat</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884848#M20821</link>
      <description>That works but you're still making that Excel file. You really can get around it if you want, up to you though.</description>
      <pubDate>Fri, 14 Jul 2023 17:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-so-that-the-ID-variable-begins-to-repeat/m-p/884848#M20821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-14T17:59:02Z</dc:date>
    </item>
  </channel>
</rss>

