<?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 requires length when informat does not in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847380#M335019</link>
    <description>I think  format yymmdd. default length is 6 .So it would spit out an error.&lt;BR /&gt;If you change data&lt;BR /&gt;2001-05-05&lt;BR /&gt;2001/5/5&lt;BR /&gt;into&lt;BR /&gt;01-5-5&lt;BR /&gt;01/5/5&lt;BR /&gt;that looks good .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _____1;&lt;BR /&gt;    informat x yymmdd.;&lt;BR /&gt;    input x;&lt;BR /&gt;    format x e8601Da.;&lt;BR /&gt;    cards;&lt;BR /&gt;2001-05-05&lt;BR /&gt;2001/5/5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data _____2;&lt;BR /&gt;    input x $10.;&lt;BR /&gt;    y = input(strip(x), yymmdd.);&lt;BR /&gt;    z = input(x, yymmdd10.);&lt;BR /&gt;    format y z e8601Da.;&lt;BR /&gt;    cards;&lt;BR /&gt;01-5-5&lt;BR /&gt;01/5/5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = _____1; run;&lt;BR /&gt;proc print data = _____2; run;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 02 Dec 2022 01:47:06 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-12-02T01:47:06Z</dc:date>
    <item>
      <title>Input function requires length when informat does not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847366#M335014</link>
      <description>&lt;P&gt;Howdy!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone explain to me why the first datastep can read the date correctly with no length specified on the format (yymmdd.), but the second datastep using input() function cannot?&amp;nbsp; And why the behavior changes for mmddyy. but only if there are no leading zeros?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _____1;
    informat x yymmdd.;
    input x;
    format x e8601Da.;
    cards;
2001-05-05
2001/5/5
;
run;
data _____2;
    input x $ 10.;
    y = input(x, yymmdd.);
    z = input(x, yymmdd10.);
    format y z e8601Da.;
    cards;
2001-05-05
2001/5/5
;
run;
proc print data = _____1; run;
proc print data = _____2; run;

data _____1;
    informat x mmddyy.;
    input x;
    format x e8601Da.;
    cards;
05/05/2001
5/5/2001
;
run;
data _____2;
    input x $ 10.;
    y = input(x, mmddyy.);
    z = input(x, mmddyy10.);
    format y z e8601Da.;
    cards;
05/05/2001
5/5/2001
;
run;
proc print data = _____1; run;
proc print data = _____2; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs        x
 1     2001-05-05
 2     2001-05-05
&amp;#12;
Obs        x         y        z
 1     2001-05-05    .    2001-05-05
 2     2001/5/5      .    2001-05-05
&amp;#12;
Obs        x
 1     2001-05-05
 2     2001-05-05
&amp;#12;
Obs        x             y             z
 1     05/05/2001             .    2001-05-05
 2     5/5/2001      2020-05-05    2001-05-05&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Warm regards,&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 22:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847366#M335014</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2022-12-01T22:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Input function requires length when informat does not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847375#M335016</link>
      <description>&lt;P&gt;Perhaps pondering why the third value "works" in this example will yield some understanding:&lt;/P&gt;
&lt;PRE&gt;data _____2;
    input x $ 10.;
    y = input(x, yymmdd.);
    z = input(x, yymmdd10.);
    format y z e8601Da.;
    cards;
2001-05-05
2001/5/5
010505
;&lt;/PRE&gt;
&lt;P&gt;INPUT as a function behaves differently than an Informat with INPUT statement. There is short comparison between the two in the documentation for the INPUT function. Look at the default width and values the informat expects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 23:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847375#M335016</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-01T23:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Input function requires length when informat does not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847380#M335019</link>
      <description>I think  format yymmdd. default length is 6 .So it would spit out an error.&lt;BR /&gt;If you change data&lt;BR /&gt;2001-05-05&lt;BR /&gt;2001/5/5&lt;BR /&gt;into&lt;BR /&gt;01-5-5&lt;BR /&gt;01/5/5&lt;BR /&gt;that looks good .&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data _____1;&lt;BR /&gt;    informat x yymmdd.;&lt;BR /&gt;    input x;&lt;BR /&gt;    format x e8601Da.;&lt;BR /&gt;    cards;&lt;BR /&gt;2001-05-05&lt;BR /&gt;2001/5/5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data _____2;&lt;BR /&gt;    input x $10.;&lt;BR /&gt;    y = input(strip(x), yymmdd.);&lt;BR /&gt;    z = input(x, yymmdd10.);&lt;BR /&gt;    format y z e8601Da.;&lt;BR /&gt;    cards;&lt;BR /&gt;01-5-5&lt;BR /&gt;01/5/5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc print data = _____1; run;&lt;BR /&gt;proc print data = _____2; run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Dec 2022 01:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847380#M335019</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-02T01:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Input function requires length when informat does not</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847383#M335021</link>
      <description>&lt;P&gt;The biggest difference is that you are using LIST MODE input.&amp;nbsp; So any width that the informat being used has is IGNORED.&amp;nbsp; Instead the whole next "word" on the line is read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length s1-s3 $100 ;
  input @1 s1
        @1 s2 :$10.
        @1 s3 :$32767.
  ;
cards;
short
really_long_word
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;OBS    s1                  s2                  s3

 1     short               short               short
 2     really_long_word    really_long_word    really_long_word
&amp;#12;
 Variables in Creation Order

#    Variable    Type    Len

1    s1          Char    100
2    s2          Char    100
3    s3          Char    100
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other concept you need to remember is that informats have a DEFAULT widths.&amp;nbsp; If you do not specify a width then the default width is used (except of course when using LIST MODE input).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing you should understand about the INPUT() function is that it does not care if the width you used on the informat is larger than the length of the string you passed in the first argument.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  string='12.3';
  number = input(string,32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So combining these in general when using a LIST MODE INPUT statement you should not bother to specify any width. And when using INPUT() function you should go ahead and use the MAXIMUM width that the informat supports.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 02:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-function-requires-length-when-informat-does-not/m-p/847383#M335021</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-02T02:53:02Z</dc:date>
    </item>
  </channel>
</rss>

