<?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: Macro Sysfunc Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672238#M201994</link>
    <description>&lt;P&gt;Kind of need to show what the expected output should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables won't "drop" leading zero. Example:&lt;/P&gt;
&lt;PRE&gt;%let a = 07;
%put a is: &amp;amp;a;&lt;/PRE&gt;
&lt;P&gt;So the idea would be to do back to the source of the values with leading zeroes and what ever "removed" them.&lt;/P&gt;
&lt;P&gt;Likely someone is reading a value that should be character, such as account numbers that often have leading zero, and not paying attention to how they are reading them. Such as abdicating responsibility and letting a procedure like Proc Import read them and create numeric variables. Prevention in the first place removes a whole lot of headaches "fixing" things later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And doing such fixes in the macro language often indicates a design flaw for the entire process. Such as placing quotes as part of a macro variable.&lt;/P&gt;
&lt;PRE&gt;%let x =23;
%let y = %sysfunc(putn(&amp;amp;x,z7.));

%put y is: &amp;amp;y.;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;%let clients = 12345; 
%let clientsb = %sysfunc(putn(&amp;amp;clients,z7.)); 
%put &amp;amp;clientsb;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Generally it is poor idea to make quotes part of the value of a macro variable.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jul 2020 22:44:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-07-24T22:44:07Z</dc:date>
    <item>
      <title>Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672231#M201989</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;My friend came to me with this issue and I wasn't sure how to unlock this one.&amp;nbsp; I mentioned I would come on SAS communities to see if anyone could help me figure this out.&amp;nbsp; The issue is he has a list that has numbers listed that when given dropped most of the leading zeros.&amp;nbsp; I wasn't sure how to pad these within a sysfunc, I do know that the put / input functions work outside of sysfunc, but I read that putc and inputc are needed for macro values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let clients = '12345'; 
%let clientsb = %sysfunc(putc(%sysfunc(inputc(&amp;amp;clients,best7.)),z7.)); 
%put &amp;amp;clientsb;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jul 2020 22:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672231#M201989</guid>
      <dc:creator>IgawaKei29</dc:creator>
      <dc:date>2020-07-24T22:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672236#M201992</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15187"&gt;@IgawaKei29&lt;/a&gt;&amp;nbsp; Hi, I think you are perhaps after this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;


%let clients = 12345; 
%let clientsb = %sysfunc(putn(%sysfunc(inputn(&amp;amp;clients,best7.)),z7.)); 
%put &amp;amp;=clientsb;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;27         %let clients = 12345;
28         %let clientsb = %sysfunc(putn(%sysfunc(inputn(&amp;amp;clients,best7.)),z7.));
29         %put &amp;amp;=clientsb;
CLIENTSB=0012345
30         &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jul 2020 22:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672236#M201992</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-07-24T22:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672238#M201994</link>
      <description>&lt;P&gt;Kind of need to show what the expected output should be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables won't "drop" leading zero. Example:&lt;/P&gt;
&lt;PRE&gt;%let a = 07;
%put a is: &amp;amp;a;&lt;/PRE&gt;
&lt;P&gt;So the idea would be to do back to the source of the values with leading zeroes and what ever "removed" them.&lt;/P&gt;
&lt;P&gt;Likely someone is reading a value that should be character, such as account numbers that often have leading zero, and not paying attention to how they are reading them. Such as abdicating responsibility and letting a procedure like Proc Import read them and create numeric variables. Prevention in the first place removes a whole lot of headaches "fixing" things later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And doing such fixes in the macro language often indicates a design flaw for the entire process. Such as placing quotes as part of a macro variable.&lt;/P&gt;
&lt;PRE&gt;%let x =23;
%let y = %sysfunc(putn(&amp;amp;x,z7.));

%put y is: &amp;amp;y.;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;%let clients = 12345; 
%let clientsb = %sysfunc(putn(&amp;amp;clients,z7.)); 
%put &amp;amp;clientsb;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Generally it is poor idea to make quotes part of the value of a macro variable.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 22:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672238#M201994</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-24T22:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672239#M201995</link>
      <description>&lt;P&gt;Ideally you'd be able to remove quotes from the macro variable which simplifies the problem. If you can't you can remove them using dequote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let clients = 12345; 
%let clientsb = %sysfunc(putn(&amp;amp;clients,z7.)); 
%put &amp;amp;clientsb;


%let clients = '12345'; 
%let clientsb = %sysfunc(putn(%sysfunc(dequote(&amp;amp;clients)), z7.));
%put &amp;amp;clientsb;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15187"&gt;@IgawaKei29&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;My friend came to me with this issue and I wasn't sure how to unlock this one.&amp;nbsp; I mentioned I would come on SAS communities to see if anyone could help me figure this out.&amp;nbsp; The issue is he has a list that has numbers listed that when given dropped most of the leading zeros.&amp;nbsp; I wasn't sure how to pad these within a sysfunc, I do know that the put / input functions work outside of sysfunc, but I read that putc and inputc are needed for macro values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let clients = '12345'; 
%let clientsb = %sysfunc(putc(%sysfunc(inputc(&amp;amp;clients,best7.)),z7.)); 
%put &amp;amp;clientsb;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 22:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672239#M201995</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-24T22:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672245#M201998</link>
      <description>&lt;P&gt;Like most posters, I don't believe that quotes are really part of the value.&amp;nbsp; And if they are,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;has shown you a function to remove them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, you don't need any %SYSFUNCs to get the result.&amp;nbsp; Just keep in mind that macro variable values are strings:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let clients = 12345;
%let clientsb = %substr(0000000&amp;amp;clients, %length(&amp;amp;clients) + 1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jul 2020 23:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672245#M201998</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-07-24T23:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672265#M202009</link>
      <description>&lt;P&gt;Quotes are not needed in macro variables.&amp;nbsp; You need quotes in SAS code (and most languages) so the parser knows you meant a string and not a number. But the macro processor only works on text so no quotes are needed.&amp;nbsp; And if you include them they are part of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INPUTC() function needs a character informat since it generates a character result but you have given it a numeric informat.&amp;nbsp; The PUTC() functions needs a character format since it operates on character values but you have given it a numeric format.&amp;nbsp; Since the %SYSFUNC() macro function does not surface the error messages your code just silently does nothing to the original string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there is no need to use the INPUTN() function to turn a string of digits into a number.&amp;nbsp; Just use the string of digits in a place where a number is expected and it will be treated as a number.&amp;nbsp; Also note that there is no "BEST" informat.&amp;nbsp; If you use that name it is just translated into a request to use the default numeric informat.&amp;nbsp; BEST is the name of a format that makes an attempt to convert a number into a string of characters in the best possible way to fit the width specified.&amp;nbsp; But SAS only has one format for storing numbers, floating point, so there is no "best" way to convert the string into a number.&amp;nbsp; Instead the string is just converted into THE number it represents.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the PUTN() function to treat the string of digits as a number and convert it into a fixed length string of digits that represents the same number only padded with leading zeros.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let clients = 12345 ; 
%let clientsb = %sysfunc(putn(&amp;amp;clients,z7.)); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 18:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672265#M202009</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-25T18:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Sysfunc Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672481#M202123</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;I really appreciate your insight on this.&amp;nbsp; Gives us both a perspective on macros and understanding how to deploy them properly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 09:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Sysfunc-Question/m-p/672481#M202123</guid>
      <dc:creator>IgawaKei29</dc:creator>
      <dc:date>2020-07-27T09:43:26Z</dc:date>
    </item>
  </channel>
</rss>

