<?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: How to create a variable indexed with the row number? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720530#M223211</link>
    <description>&lt;P&gt;Or control the values a bit better:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data want;
    set have;
    newvariable=cats('c_',put(_n_, z2.));
run;&lt;/LI-CODE&gt;
&lt;P&gt;Assuming you know there are fewer than 100 records.&lt;/P&gt;
&lt;P&gt;This gives you C_01, C_02, ... C_15.&lt;/P&gt;
&lt;P&gt;Which will sort properly and, IMHO, looks a bit nicer.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Feb 2021 18:18:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-19T18:18:04Z</dc:date>
    <item>
      <title>How to create a variable indexed with the row number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720450#M223187</link>
      <description>I have a dataset with one variable that is student roll number. All the observations are distinct and there are no duplicates. Now I want to create another variable indexed with the row number. Like if I have 15 rows with 15 different roll numbers. Then my new variable should take value c_1 against row 1, c_2 against row 2...and so on till c_15 against row 15. How do I acheive this? Thank you!</description>
      <pubDate>Fri, 19 Feb 2021 13:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720450#M223187</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-02-19T13:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable indexed with the row number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720452#M223188</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    newvariable=cats('c_',_n_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;... if I am understanding you properly&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If I may be so bold as to point out a disadvantage of doing things this way ... NEWVARIABLE doesn't sort properly, if you sort NEWVARIABLE it will come out as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c_1&lt;/P&gt;
&lt;P&gt;c_10&lt;/P&gt;
&lt;P&gt;c_11&lt;/P&gt;
&lt;P&gt;c_12&lt;/P&gt;
&lt;P&gt;c_13&lt;/P&gt;
&lt;P&gt;c_14&lt;/P&gt;
&lt;P&gt;c_15&lt;/P&gt;
&lt;P&gt;c_2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you just make newvariable numeric and assign it integers 1 through 15?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 13:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720452#M223188</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-19T13:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a variable indexed with the row number?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720530#M223211</link>
      <description>&lt;P&gt;Or control the values a bit better:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data want;
    set have;
    newvariable=cats('c_',put(_n_, z2.));
run;&lt;/LI-CODE&gt;
&lt;P&gt;Assuming you know there are fewer than 100 records.&lt;/P&gt;
&lt;P&gt;This gives you C_01, C_02, ... C_15.&lt;/P&gt;
&lt;P&gt;Which will sort properly and, IMHO, looks a bit nicer.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 18:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-variable-indexed-with-the-row-number/m-p/720530#M223211</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-19T18:18:04Z</dc:date>
    </item>
  </channel>
</rss>

