<?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 create dummy rows based on certain conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841761#M332839</link>
    <description>&lt;P&gt;I have a sneaking suspicion that if you turn this&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;Tech Clients&lt;/TD&gt;
&lt;TD&gt;Legal Clients&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;54&lt;/TD&gt;
&lt;TD&gt;35&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;87564&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;into something that looks more like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Client_type Count,&lt;/P&gt;
&lt;P&gt;where Client_type has values of "Tech" and "Legal" that likely joining on ID and Client_type would make more sense in the long run. You don't show what the table with the commission information actually looks like. Your desired table is likely going to be a bit awkward to work with for many purposes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this were my data I would do something more like:&lt;/P&gt;
&lt;PRE&gt;data have;
  input ID $	TechClients	LegalClients;
datalines;
12345	54	35
87564	20	100
;
proc transpose data=have out=trans;
   by id;
run;
data need;
   set trans;
   length ClientType $ 8;
   if _name_='TechClients' then ClientType='Tech';
   if _name_='LegalClients' then ClientType='Legal';
   Rename Col1=Clients;
   drop _name_;
run;

Data commission;
  input id $ Commision_type $ Commission;
datalines;
12345 Legal 5000
12345 Tech  10000
87564 Legal 8000
;

proc sql;
   create table want as
   select a.id,a.Commision_type, a.commission, b.clients
   from commission as a
        left join
        need as b
        on a.id=b.id and
           b.clienttype=a.Commision_type

   
   ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Which would allow me to display "dummy row" with something like this if were needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=want;
   class id Commision_type;
   var commission  clients;
   table id='',
         Commision_type*(commission  clients)*sum=''
         /misstext='0' box='Id'
   ;
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Oct 2022 20:33:43 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-10-31T20:33:43Z</dc:date>
    <item>
      <title>How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841740#M332831</link>
      <description>&lt;P&gt;How can I use PROC SQL to create dummy rows based on certain conditions?&lt;/P&gt;&lt;P&gt;I have a table that looks like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Tech Clients&lt;/TD&gt;&lt;TD&gt;Legal Clients&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87564&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I left join into this table a table that has commission information which creates a table that looks like this:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Tech Clients&lt;/TD&gt;&lt;TD&gt;Legal Clients&lt;/TD&gt;&lt;TD&gt;Commission&lt;/TD&gt;&lt;TD&gt;Commission Type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;10000&lt;/TD&gt;&lt;TD&gt;Tech&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;5000&lt;/TD&gt;&lt;TD&gt;Legal&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87564&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;8000&lt;/TD&gt;&lt;TD&gt;Legal&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;However, if someone is missing a commission type in the commission table, such as with ID 87564 who doesn't have a tech commission, they simply don't have a row for tech commission in the joined table. How do I create a table like the one below where, if a person is missing Tech or Legal commission in the commissions table, a row is still created for them where the commission amount is 0?&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Tech Clients&lt;/TD&gt;&lt;TD&gt;Legal Clients&lt;/TD&gt;&lt;TD&gt;Commission&lt;/TD&gt;&lt;TD&gt;Commission Type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;10000&lt;/TD&gt;&lt;TD&gt;Tech&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12345&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;5000&lt;/TD&gt;&lt;TD&gt;Legal&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87564&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Tech&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87564&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;8000&lt;/TD&gt;&lt;TD&gt;Legal&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 31 Oct 2022 19:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841740#M332831</guid>
      <dc:creator>alicezwang96</dc:creator>
      <dc:date>2022-10-31T19:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841757#M332837</link>
      <description>&lt;P&gt;Is it a requirement to use Proc SQL?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 20:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841757#M332837</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-31T20:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841758#M332838</link>
      <description>&lt;P&gt;I wrote that because the rest of my query is written with PROC SQL, but it's not necessarily a requirement&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 20:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841758#M332838</guid>
      <dc:creator>alicezwang96</dc:creator>
      <dc:date>2022-10-31T20:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841761#M332839</link>
      <description>&lt;P&gt;I have a sneaking suspicion that if you turn this&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;Tech Clients&lt;/TD&gt;
&lt;TD&gt;Legal Clients&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12345&lt;/TD&gt;
&lt;TD&gt;54&lt;/TD&gt;
&lt;TD&gt;35&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;87564&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;into something that looks more like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Client_type Count,&lt;/P&gt;
&lt;P&gt;where Client_type has values of "Tech" and "Legal" that likely joining on ID and Client_type would make more sense in the long run. You don't show what the table with the commission information actually looks like. Your desired table is likely going to be a bit awkward to work with for many purposes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this were my data I would do something more like:&lt;/P&gt;
&lt;PRE&gt;data have;
  input ID $	TechClients	LegalClients;
datalines;
12345	54	35
87564	20	100
;
proc transpose data=have out=trans;
   by id;
run;
data need;
   set trans;
   length ClientType $ 8;
   if _name_='TechClients' then ClientType='Tech';
   if _name_='LegalClients' then ClientType='Legal';
   Rename Col1=Clients;
   drop _name_;
run;

Data commission;
  input id $ Commision_type $ Commission;
datalines;
12345 Legal 5000
12345 Tech  10000
87564 Legal 8000
;

proc sql;
   create table want as
   select a.id,a.Commision_type, a.commission, b.clients
   from commission as a
        left join
        need as b
        on a.id=b.id and
           b.clienttype=a.Commision_type

   
   ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Which would allow me to display "dummy row" with something like this if were needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=want;
   class id Commision_type;
   var commission  clients;
   table id='',
         Commision_type*(commission  clients)*sum=''
         /misstext='0' box='Id'
   ;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Oct 2022 20:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841761#M332839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-31T20:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841762#M332840</link>
      <description>&lt;P&gt;Ok. Of course, you can do this directly in the join process, but you haven't posted the data being joined against.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, in the original question. Here is an easy way to get the desired number of observations. From there, you can easily insert the desired amounts and counts in the 'inserted' obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID TechClients LegalClients Commission CommissionType $;
datalines;
12345 54 35  10000 Tech  
12345 54 35  5000  Legal 
87564 0  100 8000  Legal 
;

proc summary data = have completetypes nway;
   class ID CommissionType;
   var TechClients LegalClients Commission;
   output out = want(drop = _:) sum=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Oct 2022 20:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841762#M332840</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-31T20:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create dummy rows based on certain conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841780#M332844</link>
      <description>&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;data Clients;&lt;BR /&gt;input ID TechClients LegalClients ;&lt;BR /&gt;datalines;&lt;BR /&gt;12345 54 35 &lt;BR /&gt;87564 20 100&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data ClientType;&lt;BR /&gt;input CType$;&lt;BR /&gt;datalines;&lt;BR /&gt;Tech &lt;BR /&gt;Legal &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;BR /&gt;Create table ClientsWithClientType as &lt;BR /&gt;Select * from Clients&lt;BR /&gt;cross join ClientType&lt;BR /&gt;;Quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Commission;&lt;BR /&gt;input ID Commission CommissionType $;&lt;BR /&gt;datalines;&lt;BR /&gt;12345 10000 Tech &lt;BR /&gt;12345 5000 Legal &lt;BR /&gt;87564 8000 Legal &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;BR /&gt;Create table Output as &lt;BR /&gt;Select &lt;BR /&gt;a.Id&lt;BR /&gt;, case when b.Commission=. then 0 else a.TechClients end as TechClients&lt;BR /&gt;, a.LegalClients &lt;BR /&gt;, coalesce(b.Commission,0) as Commission &lt;BR /&gt;, a.CType&lt;BR /&gt;from ClientsWithClientType as a&lt;BR /&gt;left join Commission as b&lt;BR /&gt;on a.Id=b.Id and a.Ctype=b.CommissionType&lt;BR /&gt;order by Id, Ctype desc&lt;BR /&gt;;Quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 255pt;" border="0" width="345" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD width="69" height="19" class="xl65" style="height: 14.6pt; width: 51pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="69" class="xl65" style="border-left: none; width: 51pt;"&gt;TechClients&lt;/TD&gt;
&lt;TD width="69" class="xl65" style="border-left: none; width: 51pt;"&gt;LegalClients&lt;/TD&gt;
&lt;TD width="69" class="xl65" style="border-left: none; width: 51pt;"&gt;Commission&lt;/TD&gt;
&lt;TD width="69" class="xl65" style="border-left: none; width: 51pt;"&gt;CType&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.6pt; border-top: none;"&gt;12345&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;54&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;35&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;10000&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Tech&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.6pt; border-top: none;"&gt;12345&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;54&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;35&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5000&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Legal&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.6pt; border-top: none;"&gt;87564&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Tech&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.6pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.6pt; border-top: none;"&gt;87564&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;20&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;8000&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;Legal&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 31 Oct 2022 22:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-dummy-rows-based-on-certain-conditions/m-p/841780#M332844</guid>
      <dc:creator>SK_11</dc:creator>
      <dc:date>2022-10-31T22:58:35Z</dc:date>
    </item>
  </channel>
</rss>

