<?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 Create new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686432#M208298</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two datasets, lets say dataset abc and dataset def&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I am trying to create a new string variable named: openflag in dataset abc, and the value to be 1 for the records. Can anyone check if my steps are right?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data abc;&lt;BR /&gt;set abc;&lt;BR /&gt;openflag = 1;&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second I want to right join dataset abc with dataset def (keep all the records from def and those matching values from abc), let's say the new dataset after join steps is NEW. Now I have openflag in NEW, I wonder how to replace the missing values into 0? Thanks very much.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Sep 2020 17:00:30 GMT</pubDate>
    <dc:creator>yichentian226</dc:creator>
    <dc:date>2020-09-24T17:00:30Z</dc:date>
    <item>
      <title>Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686432#M208298</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two datasets, lets say dataset abc and dataset def&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I am trying to create a new string variable named: openflag in dataset abc, and the value to be 1 for the records. Can anyone check if my steps are right?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data abc;&lt;BR /&gt;set abc;&lt;BR /&gt;openflag = 1;&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second I want to right join dataset abc with dataset def (keep all the records from def and those matching values from abc), let's say the new dataset after join steps is NEW. Now I have openflag in NEW, I wonder how to replace the missing values into 0? Thanks very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 17:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686432#M208298</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-24T17:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686436#M208300</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318223"&gt;@yichentian226&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two datasets, lets say dataset abc and dataset def&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First I am trying to create a new string variable named: openflag in dataset abc, and the value to be 1 for the records. Can anyone check if my steps are right?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data abc;&lt;BR /&gt;set abc;&lt;BR /&gt;openflag = 1;&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can check this yourself. Just run the code and see if you get the desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Second I want to right join dataset abc with dataset def (keep all the records from def and those matching values from abc), let's say the new dataset after join steps is NEW. Now I have openflag in NEW, I wonder how to replace the missing values into 0?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you referring to missing values because the join found no records in the left data set? Then something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table new as select *.
    case when missing(abc.openflag) then 0 else abc.openflag as openflag1
    from abc right join def on
     /* you&amp;nbsp;have&amp;nbsp;to&amp;nbsp;specify&amp;nbsp;the&amp;nbsp;ON condition&amp;nbsp;as&amp;nbsp;your&amp;nbsp;text&amp;nbsp;didn't&amp;nbsp;really&amp;nbsp;mention&amp;nbsp;what&amp;nbsp;it&amp;nbsp;was&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;abc.something=def.something;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2020 17:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686436#M208300</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-24T17:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686450#M208307</link>
      <description>&lt;P&gt;This is very helpful thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 17:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable/m-p/686450#M208307</guid>
      <dc:creator>yichentian226</dc:creator>
      <dc:date>2020-09-24T17:50:36Z</dc:date>
    </item>
  </channel>
</rss>

