<?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: re: Add Row Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268414#M53133</link>
    <description>&lt;P&gt;It is about Cartesian Product of SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Region $	Level	Cost;
cards;
South	2	132
South	3	143
South	4	100
North	1	200
North	2	210
North	3	187
North	4	178
;
run;

proc sql;
select a.*,b.cost
 from (
  select * 
   from (select distinct Region from have),
        (select distinct Level  from have)
       ) 
       as a left join have as b 
        on a.Region=b.Region  and a.Level=b.Level  ;
quit;
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 May 2016 01:21:41 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-05-05T01:21:41Z</dc:date>
    <item>
      <title>re: Add Row Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268391#M53122</link>
      <description>&lt;P&gt;Hi....I have a dataset that I am trying to add a row for each region if Level =1 is missing. The objective is to have 4 records for each Region and Levels 2, 3 and 4 will always appear as these Levels are manditory whereas Level=1 is optional. If Level=1 is missing for the Region, then a new recorded is added so that Levels 1, 2 ,3 and 4 appear where all fields appear blank except for the field Level which will have a "1" and the Region.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code I have tried is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data New;&lt;/P&gt;
&lt;P&gt;Set New;&lt;/P&gt;
&lt;P&gt;By Region;&lt;/P&gt;
&lt;P&gt;If Level ^=1 then do:&lt;/P&gt;
&lt;P&gt;Region =Region;&lt;/P&gt;
&lt;P&gt;Level=1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="192" style="width: 144pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="3" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="border: 0px black; border-image: none; width: 48pt; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Region&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Level&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Cost&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;132&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;143&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;100&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;200&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;210&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;187&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;178&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="192" style="width: 144pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="3" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="border: 0px black; border-image: none; width: 48pt; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Region&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Level&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border: 0px black; border-image: none; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Cost&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;132&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;143&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;South&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;100&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;200&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;210&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;187&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" style="border: 0px black; border-image: none; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;North&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border: 0px black; border-image: none; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;178&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 22:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268391#M53122</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2016-05-04T22:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: re: Add Row Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268396#M53126</link>
      <description>&lt;P&gt;If you have all the levels at some point in your data set you can use the sparse option in proc freq.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table region*level/sparse out=want;
weight cost;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2016 22:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268396#M53126</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-04T22:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: re: Add Row Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268414#M53133</link>
      <description>&lt;P&gt;It is about Cartesian Product of SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Region $	Level	Cost;
cards;
South	2	132
South	3	143
South	4	100
North	1	200
North	2	210
North	3	187
North	4	178
;
run;

proc sql;
select a.*,b.cost
 from (
  select * 
   from (select distinct Region from have),
        (select distinct Level  from have)
       ) 
       as a left join have as b 
        on a.Region=b.Region  and a.Level=b.Level  ;
quit;
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 May 2016 01:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Add-Row-Data-Step/m-p/268414#M53133</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-05T01:21:41Z</dc:date>
    </item>
  </channel>
</rss>

