<?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: _N_ to character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350991#M81660</link>
    <description>&lt;P&gt;Like this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Test Data Set */
data have;
   do i = 1 to 10;
      output;
   end;
run;

/* Use CATS function on _N_ to convert to character variable */
data want;
   length N $8.;
   set have;
   N = cats(_N_);
run;

/* Use PROC CONTENTS to verify that N is a character Variable */
proc contents data = want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2017 19:17:09 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-04-18T19:17:09Z</dc:date>
    <item>
      <title>_N_ to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350989#M81659</link>
      <description>&lt;P&gt;Why am I getting this error message? I need to create a new ID based on the _N_ observation variable. and I'd like the new variable to be a character variable. Is there a cleaner way to do this without the error message?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2300 data dataprep.comboIdentifier ;&lt;BR /&gt;2301 format UniqueID $3. ;&lt;BR /&gt;2302 set dataprep.comboIdentifier ;&lt;BR /&gt;2303 UniqueID=put(_N_,$3.) ;&lt;BR /&gt;WARNING: Variable _N_ has already been defined as numeric.&lt;BR /&gt;2304 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 19:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350989#M81659</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-04-18T19:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350991#M81660</link>
      <description>&lt;P&gt;Like this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Test Data Set */
data have;
   do i = 1 to 10;
      output;
   end;
run;

/* Use CATS function on _N_ to convert to character variable */
data want;
   length N $8.;
   set have;
   N = cats(_N_);
run;

/* Use PROC CONTENTS to verify that N is a character Variable */
proc contents data = want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 19:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350991#M81660</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-18T19:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350997#M81661</link>
      <description>&lt;P&gt;Reason: _N_&lt;SPAN&gt;&amp;nbsp;is numeric variable and your $3. is character format ,So they are not matched&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set sashelp.class;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;id=left(_n_); /*or this*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;UniqueID=put(_N_,3.) ;/*remove the $ in the format*/&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 19:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/350997#M81661</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-18T19:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/351001#M81663</link>
      <description>&lt;P&gt;You might find it easier to work with if you insert leading zeros:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unique_ID&amp;nbsp;= put(_n_, z3.);&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 19:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/351001#M81663</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-18T19:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: _N_ to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/351003#M81664</link>
      <description>&lt;P&gt;Your use of formats is a little confused. You need to use a numeric format with a numeric value like _N_. &amp;nbsp;Also you are using a FORMAT statement where you probably meant to use a LENGTH or ATTRIB statement to define your new varaible. There is normally no need to attached $nn. formats to character varaibles. &amp;nbsp;You probably do not want to have leading spaces in your new character variable. &amp;nbsp;Also if you want your new character variable to sort in the same order as the original integer values then you should use the Z. format so that the smaller values will have leading zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataprep.comboIdentifier ;
  length UniqueID $3 ;
  set dataprep.comboIdentifier ;
  UniqueID=put(_N_,Z3.) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 19:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/N-to-character/m-p/351003#M81664</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-18T19:27:52Z</dc:date>
    </item>
  </channel>
</rss>

