<?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 How to check if an value existing in a column? and if not then add a observation to the dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216763#M53360</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set called Test and I want to check if the Site column has value of C1 or not. if not then I want to add an observation with Site = 'C1' and Value= 123. Not sure How to do it? Hope someone could give me some hint on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Test;&lt;/P&gt;&lt;P&gt;input Site $ value 10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A1 100&lt;/P&gt;&lt;P&gt;A2 102&lt;/P&gt;&lt;P&gt;B1 102&lt;/P&gt;&lt;P&gt;B2 90&lt;/P&gt;&lt;P&gt;C2 33&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 May 2015 16:19:26 GMT</pubDate>
    <dc:creator>yangtaotai</dc:creator>
    <dc:date>2015-05-18T16:19:26Z</dc:date>
    <item>
      <title>How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216763#M53360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set called Test and I want to check if the Site column has value of C1 or not. if not then I want to add an observation with Site = 'C1' and Value= 123. Not sure How to do it? Hope someone could give me some hint on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Test;&lt;/P&gt;&lt;P&gt;input Site $ value 10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A1 100&lt;/P&gt;&lt;P&gt;A2 102&lt;/P&gt;&lt;P&gt;B1 102&lt;/P&gt;&lt;P&gt;B2 90&lt;/P&gt;&lt;P&gt;C2 33&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 16:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216763#M53360</guid>
      <dc:creator>yangtaotai</dc:creator>
      <dc:date>2015-05-18T16:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216764#M53361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've seen two methods:&amp;nbsp; &lt;/P&gt;&lt;P&gt;1) create a separate table to house the new records and then append&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table work.recs_to_add as&lt;/P&gt;&lt;P&gt;select distinct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'C1' as site,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 123 as value&lt;/P&gt;&lt;P&gt;from&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; test t1&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; not exists (select * from work.test where site='C1');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;insert into test(site,value)&lt;/P&gt;&lt;P&gt;select site,value from work.recs_to_add;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or 2) create a temp variable as part of a data step:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set test end=eof;&lt;/P&gt;&lt;P&gt;retain tmpSite;&lt;/P&gt;&lt;P&gt;format tmpsite $1.;&lt;/P&gt;&lt;P&gt;if _N_=1 then tmpSite='N';&lt;/P&gt;&lt;P&gt;if site='C2' then tmpsite='Y';&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;if eof and tmpsite='N' then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; site='C1';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; value=123;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 16:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216764#M53361</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2015-05-18T16:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216765#M53362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi DBailey,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and the first solution will work for my case. For the second method, because C2 may not even exist (I just randomly created the data set)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 17:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216765#M53362</guid>
      <dc:creator>yangtaotai</dc:creator>
      <dc:date>2015-05-18T17:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216766#M53363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not just do a MERGE of all of the values you want to force in?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data required ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if 0 then set test ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do site='A1','C1' ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do value=123;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge required test ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 17:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216766#M53363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-05-18T17:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216767#M53364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the reply and the reason why merge may not be the best practice for my case is I don't know if the original Test data set has 'C1' or not. If original Test data set has 'C1' then I don't want to add a duplication observation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 19:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216767#M53364</guid>
      <dc:creator>yangtaotai</dc:creator>
      <dc:date>2015-05-18T19:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216768#M53365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is the nature of a MERGE.&amp;nbsp; The records that are in both are combined instead of the concatenation that would occur if you combined them with the SET statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 21:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216768#M53365</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-05-18T21:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216769#M53366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; I see what you mean. Totally forgot the merge and always remember there is an option you could keep the duplicated obs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tao&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 May 2015 21:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216769#M53366</guid>
      <dc:creator>yangtaotai</dc:creator>
      <dc:date>2015-05-18T21:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216770#M53367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is 'if 0' means from your program?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data required ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; &lt;STRONG&gt; if 0&lt;/STRONG&gt; then set test ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; do site='A1','C1' ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do value=123;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data want ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; merge required test ;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 07:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216770#M53367</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2015-05-19T07:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an value existing in a column? and if not then add a observation to the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216771#M53368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is a method to insure that the variables in the new data step match the variable definitions in the old dataset.&lt;/P&gt;&lt;P&gt;The IF statement will treat 0 as false so it will never actually execute the SET statement, but the compiler will look at it and define all of the variables in that dataset.&lt;/P&gt;&lt;P&gt;This will prevent the variable SITE from being defined as length $2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2015 11:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-check-if-an-value-existing-in-a-column-and-if-not-then/m-p/216771#M53368</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-05-19T11:27:52Z</dc:date>
    </item>
  </channel>
</rss>

