<?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 a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456212#M115530</link>
    <description>&lt;P&gt;I am trying to create a new variable that has a value of 'A' for the first 30 observations (from 1 to 30), and a value of 'B' for the remaining 30 observations (from 31 to 60). Here it is my code and the data set:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA draft;&lt;BR /&gt;INFILE "/folders/myfolders/2017NBADraft2.txt"&lt;BR /&gt;DLM=',' FIRSTOBS=2 DSD MISSOVER;&lt;BR /&gt;INPUT LastName $ FirstName $ Team $ Position $ Birthdate :ANYDTDTE10. Height Wingspan Weight College $ Year $;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=draft;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;DATA draft;&lt;BR /&gt;SET draft;&lt;BR /&gt;IF 	Obs &amp;lt; 31 then  New = 'A';&lt;BR /&gt;ELSE IF  Obs &amp;gt; 30 then  New = 'B';&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=draft;&lt;BR /&gt;RUN; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is assigning A to all the variables and creating a new variable 'Obs'... how can I optimize this code in order to generate the desired output?&lt;/P&gt;</description>
    <pubDate>Sat, 21 Apr 2018 18:10:01 GMT</pubDate>
    <dc:creator>Miah</dc:creator>
    <dc:date>2018-04-21T18:10:01Z</dc:date>
    <item>
      <title>Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456212#M115530</link>
      <description>&lt;P&gt;I am trying to create a new variable that has a value of 'A' for the first 30 observations (from 1 to 30), and a value of 'B' for the remaining 30 observations (from 31 to 60). Here it is my code and the data set:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA draft;&lt;BR /&gt;INFILE "/folders/myfolders/2017NBADraft2.txt"&lt;BR /&gt;DLM=',' FIRSTOBS=2 DSD MISSOVER;&lt;BR /&gt;INPUT LastName $ FirstName $ Team $ Position $ Birthdate :ANYDTDTE10. Height Wingspan Weight College $ Year $;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=draft;&lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;DATA draft;&lt;BR /&gt;SET draft;&lt;BR /&gt;IF 	Obs &amp;lt; 31 then  New = 'A';&lt;BR /&gt;ELSE IF  Obs &amp;gt; 30 then  New = 'B';&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC PRINT DATA=draft;&lt;BR /&gt;RUN; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is assigning A to all the variables and creating a new variable 'Obs'... how can I optimize this code in order to generate the desired output?&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456212#M115530</guid>
      <dc:creator>Miah</dc:creator>
      <dc:date>2018-04-21T18:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456214#M115531</link>
      <description>&lt;P&gt;There is no variable OBS in your data therefor it is assigned as missing value which is the lowest posibble value&lt;/P&gt;
&lt;P&gt;and obviousley less then 31.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change OBS by _N_, which is an internal counter, and you'll get what you want.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456214#M115531</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-21T18:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456215#M115532</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;, but you don't need the extra if. i.e.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA draft;
  SET draft;
  IF  _n_ &amp;lt; 31 then  New = 'A';
  ELSE New = 'B';
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable/m-p/456215#M115532</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-04-21T18:27:31Z</dc:date>
    </item>
  </channel>
</rss>

