<?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: Adding a new column based on a logic statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333779#M75279</link>
    <description>&lt;P&gt;That would work. &amp;nbsp;However, note that by running the program without the SET statement, you have already wiped out your original data set. &amp;nbsp;You still need to re-create it first.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2017 14:02:37 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-02-17T14:02:37Z</dc:date>
    <item>
      <title>Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333742#M75258</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very new to sas and trying to add an additonal column based on a logic statement. Used this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data practice.new;&lt;BR /&gt;if ageyr &amp;lt;= 8 then young="Y";&lt;BR /&gt;else young="N";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It ended up replacing my entire column with 2 columns of ageyr and another column called young. What exactly happened? How do i make sure that everything else is not changed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 11:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333742#M75258</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-02-17T11:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333752#M75263</link>
      <description>&lt;P&gt;What entire column are you reffering to? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; And can you provide some sample data?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 11:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333752#M75263</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-17T11:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333753#M75264</link>
      <description>&lt;P&gt;Is that what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set have;
      if ageyr &amp;lt;= 8 then young="Y";
      else young="N";
      drop ageyr;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 11:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333753#M75264</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-17T11:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333755#M75266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127989"&gt;@byeh2017&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;data practice.new;&lt;BR /&gt;if ageyr &amp;lt;= 8 then young="Y";&lt;BR /&gt;else young="N";&lt;BR /&gt;run;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;data practice.new; - this statement creates a data set named 'new' in 'practice' library&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if practice.new is your source data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;u need to define practice.new in the SET statement so that SAS fetches data from it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 12:11:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333755#M75266</guid>
      <dc:creator>gauthamk28</dc:creator>
      <dc:date>2017-02-17T12:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333758#M75267</link>
      <description>&lt;P&gt;Let me repeat the most important comment you received so far.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No SET statement = no incoming data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you created PRACTICE.NEW, but based upon no incoming data (based upon only your logic statements). &amp;nbsp;If you intended to make changes to PRACTICE.NEW, it is gone. &amp;nbsp;You would need to re-create it.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 13:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333758#M75267</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-17T13:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333772#M75272</link>
      <description>&lt;P&gt;ageyr is the column im referring to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to create a new column called young that is just binary for Y and N&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 13:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333772#M75272</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-02-17T13:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333776#M75276</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i wanted to only modify the dataset I'm referring to. Do I just do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data practice.new1;
set practice.new1;
if ageyr &amp;lt;= 8 then young="Y";
else young="N";
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 13:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333776#M75276</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-02-17T13:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333778#M75278</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127989"&gt;@byeh2017&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i wanted to only modify the dataset I'm referring to. Do I just do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data practice.new1;
set practice.new1;
if ageyr &amp;lt;= 8 then young="Y";
else young="N";
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this code will add new variable YOUNG to the dataset, with value based on AGEYR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 14:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333778#M75278</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-17T14:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333779#M75279</link>
      <description>&lt;P&gt;That would work. &amp;nbsp;However, note that by running the program without the SET statement, you have already wiped out your original data set. &amp;nbsp;You still need to re-create it first.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 14:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333779#M75279</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-17T14:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333798#M75286</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127989"&gt;@byeh2017&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i wanted to only modify the dataset I'm referring to. Do I just do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data practice.new1;
set practice.new1;
if ageyr &amp;lt;= 8 then young="Y";
else young="N";
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes this should work but until you become much more comfortable with SAS I would recommend creating new data sets as you do not actuall "add" the variable but recreate the entire dataset with a new variable added. The difference may look subtle but you have already likely destroyed an existing data set once and you may do so again with the same data set name on the Set and Data lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have seen code where people were recoding values with something like:&lt;/P&gt;
&lt;P&gt;if x&amp;lt;3 then x=x-1;&lt;/P&gt;
&lt;P&gt;using the same input/output. They added a new variable and ran the code again. Added another code change. And then tried to figure out why they had negative values and zeroes they didn't expect.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 15:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333798#M75286</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-17T15:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a new column based on a logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333918#M75316</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127989"&gt;@byeh2017&lt;/a&gt;, pay attention, the meaning of each line in next skilton code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA &amp;nbsp;libref.dsname; &amp;nbsp; &amp;nbsp;&amp;lt;&amp;lt;&amp;lt; defines &lt;STRONG&gt;output&amp;nbsp;dataset&lt;/STRONG&gt; to a library given by libref, dataset name given as dsname.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; SET &amp;nbsp;libref.dsname; &amp;nbsp; &amp;nbsp;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp;&lt;SPAN&gt;defines &amp;nbsp;&lt;STRONG&gt;input &amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;dataset&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;from a library given by libref, dataset name given as dsname.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... any sas code need to produce output from input ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;RUN; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&amp;lt;&amp;lt; closes the data step&amp;nbsp;ready to check syntax and &lt;STRONG&gt;execute&lt;/STRONG&gt; .&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA and SET may be assigned to different datasets, either differ by &lt;STRONG&gt;libref&lt;/STRONG&gt; or by &lt;STRONG&gt;dsname&lt;/STRONG&gt; or by &lt;STRONG&gt;both.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In case they are both assigned to &lt;STRONG&gt;same libref and dsname&lt;/STRONG&gt;, sas will create a &lt;STRONG&gt;new&lt;/STRONG&gt; dataset and &lt;STRONG&gt;replace&lt;/STRONG&gt; the original.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also other ways to define input, beside of SET statement, like INFILE to read&lt;/P&gt;
&lt;P&gt;external (not sas) file as xxx.txt or xxx.csv or DATALINES.&lt;/P&gt;
&lt;P&gt;Anyhow, usually you need INPUT to create OUTPUT.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2017 20:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-new-column-based-on-a-logic-statement/m-p/333918#M75316</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-17T20:08:20Z</dc:date>
    </item>
  </channel>
</rss>

