<?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: input function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867632#M342677</link>
    <description>&lt;P&gt;There is a big difference between the PUT and INPUT functions on the one side and the PUTN, PUTC, INPUTN and INPUTC functions on the other.&lt;/P&gt;
&lt;P&gt;While all other functions expect numeric or character&amp;nbsp;&lt;EM&gt;expressions&lt;/EM&gt; as arguments, PUT and INPUT expect a format&amp;nbsp;&lt;EM&gt;name&lt;/EM&gt;, which is neither numeric nor character. While the N/C functions evaluate the second argument on their own during data step &lt;EM&gt;execution&lt;/EM&gt;, for PUT and INPUT the data step compiler does this during &lt;EM&gt;compilation&lt;/EM&gt; and then (IMO) implements the same mechanism used in PUT and INPUT statements. This (for me) explains the difference. PUT and INPUT are rather "compiler directives" than "normal functions".&lt;/P&gt;
&lt;P&gt;While the INPUTN functions evaluates the whole first argument, the INPUT acts like the statement and reads the next X characters from the "input stream", where X is the width of the format.&lt;/P&gt;
&lt;P&gt;An inconsistency, but explainable. Maybe an insider (&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;, can you call out to a developer?) can shed more light on this.&lt;/P&gt;</description>
    <pubDate>Sun, 02 Apr 2023 09:32:16 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-04-02T09:32:16Z</dc:date>
    <item>
      <title>input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867188#M342470</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm really puzzled here.&lt;/P&gt;
&lt;P&gt;I would expect step2/step12 would be set to missing, the solution being stepx but my output says differently &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How could SAS is able to map No to 1 knowing that only N is in the informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format fmtlib;
    value demoa    0 ='No'
                   1 ='Yes';
    invalue demob 'N'=1
                  'Y'=100;
    select demoa @demob;
run;

data demo;
    result=0; output;
    result=1; output;
run;

data demo;
    set demo;

    step1 =put(result,demoa.);
    step2 =input(step1,demob.);
    step12=input(put(result,demoa.),demob.);
    
    stepx =input(put(result,demoa1.),demob.);
    
    put 'STEP 1' step1;
    put 'STEP 2' step2;
run;

proc print data=demo;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input_put.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82187iC2FE20519743C654/image-size/medium?v=v2&amp;amp;px=400" role="button" title="input_put.JPG" alt="input_put.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 08:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867188#M342470</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-03-30T08:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867194#M342474</link>
      <description>&lt;P&gt;Since the possible arguments to your informat all have the length 1, the default length is also (implicitly) defined as 1, so it will always read only the first character of the string (unless you set another length when using the informat).&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 08:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867194#M342474</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-30T08:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867198#M342477</link>
      <description>&lt;P&gt;Thank you so much &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm never thought about it as a possibility.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 08:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867198#M342477</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-03-30T08:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867629#M342675</link>
      <description>&lt;P&gt;Dear &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was rethinking at this input thing.&lt;/P&gt;
&lt;P&gt;- For numeric and character formats, the default width is the format decode (label) width.&lt;/P&gt;
&lt;P&gt;- For a numeric informat, the default width would then be the informat code (start/end).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1/ So I was wondering what is the default width for character informat. It seems to be the informat decode width.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2/ I was also wondering on whether inputn would work the same way as input+numeric informat. And it doesn't.&lt;/P&gt;
&lt;P&gt;Actually inputn works the way I was expecting it to work. ny_inputn is set to missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format fmtlib;
    value   $ny 'N'='00'
                'Y'='11';
    invalue ny  'N'=0
                'Y'=1;
    invalue $ny 'N'='00'
                'Y'='11';
run;  

data demo;
    length ny $3;
    ny='No'; output;
    ny='Yes'; output;
run;

data demo;
   set demo;
   ny_put=put(ny,$ny.);
   ny_input_n=input(ny,ny.);
   ny_input_c=input(ny,$ny.);
   ny_inputn=inputn(ny,'ny');
   ny_inputc=inputc(ny,'$ny');
run;

proc print data=demo;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="put.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82250i7D5A3A4DE928AFFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="put.JPG" alt="put.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2023 07:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867629#M342675</guid>
      <dc:creator>xxformat_com</dc:creator>
      <dc:date>2023-04-02T07:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867632#M342677</link>
      <description>&lt;P&gt;There is a big difference between the PUT and INPUT functions on the one side and the PUTN, PUTC, INPUTN and INPUTC functions on the other.&lt;/P&gt;
&lt;P&gt;While all other functions expect numeric or character&amp;nbsp;&lt;EM&gt;expressions&lt;/EM&gt; as arguments, PUT and INPUT expect a format&amp;nbsp;&lt;EM&gt;name&lt;/EM&gt;, which is neither numeric nor character. While the N/C functions evaluate the second argument on their own during data step &lt;EM&gt;execution&lt;/EM&gt;, for PUT and INPUT the data step compiler does this during &lt;EM&gt;compilation&lt;/EM&gt; and then (IMO) implements the same mechanism used in PUT and INPUT statements. This (for me) explains the difference. PUT and INPUT are rather "compiler directives" than "normal functions".&lt;/P&gt;
&lt;P&gt;While the INPUTN functions evaluates the whole first argument, the INPUT acts like the statement and reads the next X characters from the "input stream", where X is the width of the format.&lt;/P&gt;
&lt;P&gt;An inconsistency, but explainable. Maybe an insider (&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;, can you call out to a developer?) can shed more light on this.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2023 09:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867632#M342677</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-02T09:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867641#M342684</link>
      <description>&lt;P&gt;You seem to have discovered that the INPUTN() function does not use the defualt width when the format specification does not provide one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So just make sure to specify the width when you use inputn().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ny_inputn=inputn(ny,'ny1.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make sure you only give it one character if that is all you want it to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ny_inputn=inputn(char(ny,1),'ny.');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that like the INPUT() function then INPUTN() function does not care if the informat width is larger than the length of the string being read. So this code works fine:&lt;/P&gt;
&lt;PRE&gt;61   data want;
62     string='123';
63     num1=input(string,32.);
64     num2=inputn(string,'32.');
65     put string= $quote. num1= num2=;
66   run;

string="123" num1=123 num2=123
&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Apr 2023 13:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/input-function/m-p/867641#M342684</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-02T13:41:35Z</dc:date>
    </item>
  </channel>
</rss>

