<?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: Numeric Converting to Character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785197#M250569</link>
    <description>&lt;P&gt;Use the right function for the task at hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CATS() to append the number to the macro variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CALL SYMPUTX() as it will automatically trim leading/trailing spaces and automatically convert numbers to strings.&amp;nbsp; The only reason to ever use CALL SYMPUT() is if you really want to put leading/trailing spaces into the value of your macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq1;
  set seq end=eof;
  by rx study;
  if first.rx then seq=1;
  else seq+1;
  if last.rx then call symputx(cats('seqnm',rx),seq);
  if eof then call symputx('numrx',rx);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Dec 2021 16:42:01 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-12-09T16:42:01Z</dc:date>
    <item>
      <title>Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785181#M250564</link>
      <description>&lt;P&gt;I am trying to create a macro variable, I could not&amp;nbsp; get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1639067370644.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66566iAC062A2EA569781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1639067370644.png" alt="SASuserlot_0-1639067370644.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symput('seqnm'||left(rx),compress(put(seq,8.)));
if eof then call symput('numrx',compress(put(rx,8.)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:30:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785181#M250564</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-09T16:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785186#M250568</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;left(rx)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're applying a character function to the number rx so you get that message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;CALL SYMPUTX removes extra spaces automatically and allows you to specify a local/global macro variable in comparison to CALL SYMPUT.&lt;/LI&gt;
&lt;LI&gt;Use the -l option in the PUT statement to align values to the left&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symputx('seqnm'||put(rx, 8. -l), put(seq,8. -l));
if eof then call symput('numrx', put(rx,8. -l));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a macro variable, I could not&amp;nbsp; get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1639067370644.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66566iAC062A2EA569781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1639067370644.png" alt="SASuserlot_0-1639067370644.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq;
input study rx;
cards;
2 1
3 1
1 3
3 3
1 4
2 4
;
run;

data seq1;
set seq end=eof;
by rx study;
if first.rx then seq=1;
else seq+1;
if last.rx then call symput('seqnm'||left(rx),compress(put(seq,8.)));
if eof then call symput('numrx',compress(put(rx,8.)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785186#M250568</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-09T16:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785197#M250569</link>
      <description>&lt;P&gt;Use the right function for the task at hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CATS() to append the number to the macro variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CALL SYMPUTX() as it will automatically trim leading/trailing spaces and automatically convert numbers to strings.&amp;nbsp; The only reason to ever use CALL SYMPUT() is if you really want to put leading/trailing spaces into the value of your macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq1;
  set seq end=eof;
  by rx study;
  if first.rx then seq=1;
  else seq+1;
  if last.rx then call symputx(cats('seqnm',rx),seq);
  if eof then call symputx('numrx',rx);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785197#M250569</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-09T16:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785211#M250574</link>
      <description>&lt;P&gt;Thank you, it works.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785211#M250574</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-09T17:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785212#M250575</link>
      <description>&lt;P&gt;Thank you . It works.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785212#M250575</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-09T17:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785213#M250576</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a macro variable, I could not&amp;nbsp; get my head where I am doing wrong. Getting a note 'Numeric converted to character' Please correct me. Thanks.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1639067370644.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66566iAC062A2EA569781C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1639067370644.png" alt="SASuserlot_0-1639067370644.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you count columns across the line of text that starts with 5637 (the LINE referred to in the note) until you get to 43 (the COLUMN referred to in the note) you will see the R of the variable name RX is in that position. SAS is telling you that you are using a numeric variable RX with a character function. SAS is pretty nice about attempting to do what you tell it. But sometimes the default conversion to character may not yield what you want, especially when the value is not an integer. Similar applies to using character variables that look like numbers in numeric expressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take these warnings to heart as it may mean your data is not what you actually think it is and other problems may lurk.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785213#M250576</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-09T17:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric Converting to Character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785216#M250578</link>
      <description>&lt;P&gt;Thanks for detailed explanation. I will try to follow and implement if I come across this issue again.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-Converting-to-Character/m-p/785216#M250578</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-12-09T17:40:37Z</dc:date>
    </item>
  </channel>
</rss>

