<?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: Merge dataset under conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113822#M23472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So if I have 15 SET statements, I will need 15 variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Jan 2013 21:12:42 GMT</pubDate>
    <dc:creator>Demographer</dc:creator>
    <dc:date>2013-01-03T21:12:42Z</dc:date>
    <item>
      <title>Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113818#M23468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a first dataset called "survieH" that looks like this:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 640px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="17" width="80"&gt;p1&lt;/TD&gt;&lt;TD width="80"&gt;p2&lt;/TD&gt;&lt;TD width="80"&gt;p3&lt;/TD&gt;&lt;TD width="80"&gt;p4&lt;/TD&gt;&lt;TD width="80"&gt;p5&lt;/TD&gt;&lt;TD width="80"&gt;p6&lt;/TD&gt;&lt;TD width="80"&gt;p7&lt;/TD&gt;&lt;TD width="80"&gt;p8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;0,99805395&lt;/TD&gt;&lt;TD align="right"&gt;0,99972943&lt;/TD&gt;&lt;TD align="right"&gt;0,99978889&lt;/TD&gt;&lt;TD align="right"&gt;0,99983248&lt;/TD&gt;&lt;TD align="right"&gt;0,99986097&lt;/TD&gt;&lt;TD align="right"&gt;0,99988087&lt;/TD&gt;&lt;TD align="right"&gt;0,99989295&lt;/TD&gt;&lt;TD align="right"&gt;0,99989952&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I have a second dataset called "survieF" that is similar to the first one:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 640px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="17" width="80"&gt;p1&lt;/TD&gt;&lt;TD width="80"&gt;p2&lt;/TD&gt;&lt;TD width="80"&gt;p3&lt;/TD&gt;&lt;TD width="80"&gt;p4&lt;/TD&gt;&lt;TD width="80"&gt;p5&lt;/TD&gt;&lt;TD width="80"&gt;p6&lt;/TD&gt;&lt;TD width="80"&gt;p7&lt;/TD&gt;&lt;TD width="80"&gt;p8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;0,99829433&lt;/TD&gt;&lt;TD align="right"&gt;0,99976891&lt;/TD&gt;&lt;TD align="right"&gt;0,99982696&lt;/TD&gt;&lt;TD align="right"&gt;0,99986511&lt;/TD&gt;&lt;TD align="right"&gt;0,99989035&lt;/TD&gt;&lt;TD align="right"&gt;0,9999069&lt;/TD&gt;&lt;TD align="right"&gt;0,99991557&lt;/TD&gt;&lt;TD align="right"&gt;0,99992048&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finaly, I have the main database ("bd2006") that contains many observations (30000) and several variables, which "sex" (0-1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a new dataset that merges them under the condition that if sex=1 then variable I pick the p1-p8 variables in the survieF dataset and if sex=0, I pick the other one.&lt;/P&gt;&lt;P&gt;I tried this, without succes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.bd2007; &lt;/P&gt;&lt;P&gt;set work.bd2006;&lt;/P&gt;&lt;P&gt;if _N_ EQ 1 and sex=0 then set survieH ;&amp;nbsp; &lt;/P&gt;&lt;P&gt;if _N_ EQ 1 and sex=1 then set survieF ; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I can do it by doing this, but I want to reduce the size of the dataset, so I don't think it's the best way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data survieH (keep ph1-ph8);&lt;/P&gt;&lt;P&gt;set survieH;&lt;/P&gt;&lt;P&gt;p1=ph1;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;p8=ph8;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.bd2007; &lt;/P&gt;&lt;P&gt;set work.bd2006;&lt;/P&gt;&lt;P&gt;if _N_ EQ 1 then do set survieH; set survieF ; end;&lt;/P&gt;&lt;P&gt;array ph ph1-ph8;&lt;/P&gt;&lt;P&gt;array p p1-p8;&lt;/P&gt;&lt;P&gt;do i=1 to 8;&lt;/P&gt;&lt;P&gt;if sex=0 then p(i)=ph(i);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop ph1-ph8;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 19:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113818#M23468</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-03T19:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113819#M23469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is one way using the POINT= option to prevent SAS from stopping because you read all of the P value records.&lt;/P&gt;&lt;P&gt;Added logic to force P1-P8 to be missing if SEX is neither 0 or 1.&amp;nbsp; SAS will automatically drop the variables named in the POINT= options.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data work.bd2007;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set work.bd2006;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; pointer1=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; pointer2=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if sex=0 then set survieH point=pointer1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else if sex=1 then set survieF point=pointer2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else &lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;call missing(of p1-p8);&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 19:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113819#M23469</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-03T19:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113820#M23470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, it works.&lt;/P&gt;&lt;P&gt;But I don't understand what is the purpose of pointer1 and pointer2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 20:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113820#M23470</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-03T20:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113821#M23471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The POINT= option of the SET statement uses a data step variable to allow you to dynamically directly access observations in a dataset. That is what the two pointer variables are used for.&amp;nbsp; Because we have two SET statements we need two different variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case we are always accessing the same observation because the pointer variables are always set to one.&amp;nbsp; Why it is useful for this application is that it lets you use the extra two SET statements without worrying that SAS will move past the end of one of them and cause your data step to end prematurely. Also by re-accessing the same observations from the two P value tables over and over we can reload the P1-P8 variables without having to rename them or create arrays or code DO loops to copy from the renamed variables to the desired names.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 20:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113821#M23471</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-03T20:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113822#M23472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So if I have 15 SET statements, I will need 15 variables?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113822#M23472</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-03T21:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113823#M23473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want to use POINT= option on each of them.&amp;nbsp; But if you have 15 then you probably do not want to code it this way, or you want to use a macro to generate the code for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could do your combination using PROC SQL by adding the SEX variable to the data with the P values.&amp;nbsp; Either keep the SEX variable when you are generating the P values or add it back in.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table want as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.*,b.*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have a &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select 1 as SEX,f.* from &lt;SPAN style="background-color: #ffffff;"&gt;survieF f&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; union &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select 0 as SEX,h.* from survieH h) b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.sex = b.sex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113823#M23473</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-03T21:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113824#M23474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you really need 15?&amp;nbsp; Wouldn't a single variable work just as well across all SET statements?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113824#M23474</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-01-03T21:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Merge dataset under conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113825#M23475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually I tested and it does not require different variables.&amp;nbsp; So a single pointer variable could work.&amp;nbsp; I am just used to using different variables because of the confusion that would occur if you used the same variable for options that the SET statement modifies the values such as END= or NOBS=.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-dataset-under-conditions/m-p/113825#M23475</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-03T21:45:41Z</dc:date>
    </item>
  </channel>
</rss>

