<?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: Proc SQL: Filling in missing rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879765#M82769</link>
    <description>Thanks. Very helpful.</description>
    <pubDate>Thu, 08 Jun 2023 13:39:04 GMT</pubDate>
    <dc:creator>BruceBrad</dc:creator>
    <dc:date>2023-06-08T13:39:04Z</dc:date>
    <item>
      <title>Proc SQL: Filling in missing rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879755#M82767</link>
      <description>&lt;P&gt;I have a dataset with observations for each year for each person. Some years are missing. I want to expand the file to have all years for each person (with missing values for the missing years). Can this be done with an SQL statement. The code below doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input id year var;
cards;
1 2001 3
1 2002 5
1 2003 7
2 2002 4
2 2003 6
;
run;

data years;
input year;
cards;
2001
2002
2003
;
run;

data desired;
input id year var;
cards;
1 2001 3
1 2002 5
1 2003 7
2 2001 .
2 2002 4
2 2003 6
;

/* this doesn't add in the missing row */;
proc sql;
  create table comb as
  select years.year, one.id, one.var from
  years left join one
  on one.year = years.year
  order by id,year ;
quit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 13:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879755#M82767</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2023-06-08T13:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Filling in missing rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879762#M82768</link>
      <description>&lt;P&gt;One way is to make a cartesian product between id and years firs, then do the left join from your original table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table comb as
  select id_years.year, id_years.id, one.var from
  (select id, years.year 
	from (select distinct id from one), years) id_years
left join one
  on one.id = id_years.id and 
	one.year = id_years.year
  order by id,year ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 13:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879762#M82768</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-06-08T13:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: Filling in missing rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879765#M82769</link>
      <description>Thanks. Very helpful.</description>
      <pubDate>Thu, 08 Jun 2023 13:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-Filling-in-missing-rows/m-p/879765#M82769</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2023-06-08T13:39:04Z</dc:date>
    </item>
  </channel>
</rss>

