<?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 statement: informat question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52338#M11059</link>
    <description>&amp;gt;whenever I use informat for character variable in the input statement, SAS will treat it as formatted input, unless I use colon. It makes a real difference when my values have different length.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Yes. you are right. But the length of variable is the length you defined in format, that is not different length when you use colon in your input statement.There is an important thing you need to remember(i.e. when you use length statement and informat statement before input statement, input method is identical with colon input method just as Cynthia mentioned),and once the character varible enters the PDV ,its length will not allow to change afer data step.&lt;BR /&gt;
&lt;BR /&gt;
Now let's take a look at your example.&lt;BR /&gt;
In your code ,'hours'is list input, 'Firstname' is list input(which has eight length sas default),'Lastname' is formatted input ( which will ignore the delimiter such as blank, and input until the fifth character, So you will get 'Lee 1' not 'Lee', you should add colon before $5. such as : $5.), The colon in ' : $5. ' will stop read the data when encounter delimiter ( blank and so on),but the length of  variable is still 5.&lt;BR /&gt;
&lt;BR /&gt;
Hope this will help you a little bit.&lt;BR /&gt;
Cynthia gives some value reference about it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
    <pubDate>Fri, 24 Dec 2010 01:30:53 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-12-24T01:30:53Z</dc:date>
    <item>
      <title>Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52330#M11051</link>
      <description>Greetings:&lt;BR /&gt;
Got confused here while learning how informat works in reading raw data files. Could any expert give a hint?&lt;BR /&gt;
&lt;BR /&gt;
Raw data in a txt file:&lt;BR /&gt;
NewYork 12&lt;BR /&gt;
LA 24&lt;BR /&gt;
&lt;BR /&gt;
Here is what I tried first.&lt;BR /&gt;
data work.ny;&lt;BR /&gt;
	infile ny;&lt;BR /&gt;
	input city $7. visit;&lt;BR /&gt;
run;&lt;BR /&gt;
This landed me with only the first row plus an error message:&lt;BR /&gt;
SAS went to a new line when INPUT statement reached past the end of a line.&lt;BR /&gt;
&lt;BR /&gt;
Could someone help me to understand why would SAS reach past the end of the first line at all?  I know if "LA" is "Seattle" (a longer value), my code will work fine so I don't think the first ob is the problem. To stop SAS reaching past the end, I tried MISSOVER. This did bring in a second row with values missing. In the end, I had to use a colon modifier. &lt;BR /&gt;
&lt;BR /&gt;
My SAS book says "The informat in modified list input determines only the length of the variable, not the number of columns that are read. " But in this case if I don't use an informat for city, the original code will work fine so I'm puzzled.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your time!</description>
      <pubDate>Sun, 19 Dec 2010 17:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52330#M11051</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-12-19T17:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52331#M11052</link>
      <description>You're just a little confused.  You can find a nice description at:&lt;BR /&gt;
&lt;A href="http://support.sas.com/publishing/pubcat/chaps/58369.pdf" target="_blank"&gt;http://support.sas.com/publishing/pubcat/chaps/58369.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
The problem is that you are NOT using the method the statement describes.  For modified list input you would have to include a colon in your input statement.  e.g.:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
input city : $7. visit;&lt;BR /&gt;
&lt;BR /&gt;
Otherwise, yes, SAS will read all seven characters for city, regardless of whether they include imbeded spaces or not.  If you also have imbeded spaces, then you would also have to include the ampersand modifier.&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Sun, 19 Dec 2010 19:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52331#M11052</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-12-19T19:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52332#M11053</link>
      <description>Hi.&lt;BR /&gt;
In SAS ,there are four input method : list input, formatted input, column input , named input.&lt;BR /&gt;
The difference you refer to is between list input and formatted input.Art has some details for it.&lt;BR /&gt;
So If you understand these four input way,then will process complicated data perfently.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Mon, 20 Dec 2010 03:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52332#M11053</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-20T03:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52333#M11054</link>
      <description>Thanks to you both, Art and Ksharp. The recommended file is very easy to follow.&lt;BR /&gt;
Just to confirm:&lt;BR /&gt;
&lt;BR /&gt;
My SAS Certification book says 'The colon (:) modifier is used to read nonstandard data values and character values that are longer than eight characters, but which contain no embedded blanks.' It almost makes me think if character values are shorter than 8 bytes and do not have embedded blanks, the modifiers are not necessary.&lt;BR /&gt;
&lt;BR /&gt;
Now after our earlier discussion, it seems that I have to use : or &amp;amp; so SAS understands I'm not trying to read data with formatted input? I guess it's more of an issue when the variable starts from column 1 otherwise by looking at the pointer portion, it's not hard to tell input method.&lt;BR /&gt;
&lt;BR /&gt;
Many thanks!</description>
      <pubDate>Tue, 21 Dec 2010 06:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52333#M11054</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-12-21T06:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52334#M11055</link>
      <description>Tested more and confirmed the answer to my previous post should be yes. Thanks for the learning.</description>
      <pubDate>Wed, 22 Dec 2010 04:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52334#M11055</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-12-22T04:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52335#M11056</link>
      <description>&amp;gt;if character values are shorter than 8 bytes and do not have embedded blanks, the modifiers are not necessary.&lt;BR /&gt;
&lt;BR /&gt;
That is only suitable for list input .that is mean list input ' input a $ ' is the same as modified input ' input a : $8.' .Once you use formatted then maybe you would use colon as Art mentioned '  input a : $7.'.</description>
      <pubDate>Wed, 22 Dec 2010 08:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52335#M11056</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-22T08:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52336#M11057</link>
      <description>Thanks for the additional explanation! I noticed that whenever I use informat for character variable in the input statement, SAS will treat it as formatted input, unless I use colon. It makes a real difference when my values have different length.&lt;BR /&gt;
&lt;BR /&gt;
Here's my quick test:&lt;BR /&gt;
Raw data:&lt;BR /&gt;
Andy Lee 150&lt;BR /&gt;
Adam Jack 200&lt;BR /&gt;
Mary Jacob 300&lt;BR /&gt;
&lt;BR /&gt;
When I test   Input Firstname$ Lastname $5. Hours;   the lastname for the first row shows Lee 1 (because SAS grabbed 5 characters) and the value for hours = 50, even though I "think" my code is using modified list input and I was hoping SAS stops reading for my lastname field when it encounters the space after Lee. In short, have to use the colon to get the data in right. Hope this helps the next puzzled student.</description>
      <pubDate>Thu, 23 Dec 2010 04:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52336#M11057</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-12-23T04:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52337#M11058</link>
      <description>Hi:&lt;BR /&gt;
  There is another way to read your data, using simple list input (not formatted input), as described here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001066690.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001066690.htm&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
 Although you can use mixed input types, when you used $5. to read LASTNAME, you changed from list input to "formatted input", as described here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001052077.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001052077.htm&lt;/A&gt;  &lt;BR /&gt;
                 &lt;BR /&gt;
Note that, as it says at the end of the topic -- SAS read formatted input until it has read the number of positions specified by the INFORMAT. In your case, $5. was considered to be the INFORMAT for the LASTNAME field.&lt;BR /&gt;
 &lt;BR /&gt;
So when you had &lt;BR /&gt;
[pre]&lt;BR /&gt;
input firstname $ lastname $5. ... ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
You started with simple list input for FIRSTNAME, and then, switched to formatted input for LASTNAME. I'm not sure how you read HOURS -- with formatted or list input.&lt;BR /&gt;
 &lt;BR /&gt;
You can use a LENGTH statement with simple list input to specify the maximum length for a character variable that you are going to read with list input. If you specify the length, then list input will read until it hits a delimiter (the default delimiter for list input is a space or blank -- although, you can change it with the DLM option).&lt;BR /&gt;
 &lt;BR /&gt;
The program below reads your data without using the colon modifier.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data hourdata;&lt;BR /&gt;
  length firstname $8 lastname $15;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input firstname $ lastname $ hours;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
Andy Lee 150&lt;BR /&gt;
Adam Jack 200&lt;BR /&gt;
Mary Jacob 300&lt;BR /&gt;
John Jingleheimer 400&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                        &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc contents data=hourdata;&lt;BR /&gt;
  title 'PROC CONTENTS';&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
proc print data=hourdata;&lt;BR /&gt;
  title 'PROC PRINT';&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 23 Dec 2010 06:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52337#M11058</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-12-23T06:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52338#M11059</link>
      <description>&amp;gt;whenever I use informat for character variable in the input statement, SAS will treat it as formatted input, unless I use colon. It makes a real difference when my values have different length.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Yes. you are right. But the length of variable is the length you defined in format, that is not different length when you use colon in your input statement.There is an important thing you need to remember(i.e. when you use length statement and informat statement before input statement, input method is identical with colon input method just as Cynthia mentioned),and once the character varible enters the PDV ,its length will not allow to change afer data step.&lt;BR /&gt;
&lt;BR /&gt;
Now let's take a look at your example.&lt;BR /&gt;
In your code ,'hours'is list input, 'Firstname' is list input(which has eight length sas default),'Lastname' is formatted input ( which will ignore the delimiter such as blank, and input until the fifth character, So you will get 'Lee 1' not 'Lee', you should add colon before $5. such as : $5.), The colon in ' : $5. ' will stop read the data when encounter delimiter ( blank and so on),but the length of  variable is still 5.&lt;BR /&gt;
&lt;BR /&gt;
Hope this will help you a little bit.&lt;BR /&gt;
Cynthia gives some value reference about it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Fri, 24 Dec 2010 01:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52338#M11059</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-24T01:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52339#M11060</link>
      <description>Cynthia and Ksharp:&lt;BR /&gt;
Thank you so much for all the detailed clarification!&lt;BR /&gt;
I tested your suggestions and they all make sense to me now.I'm glad you are here for the beginners :).</description>
      <pubDate>Fri, 24 Dec 2010 06:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52339#M11060</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2010-12-24T06:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Input statement: informat question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52340#M11061</link>
      <description>Hi mnew&lt;BR /&gt;
&lt;BR /&gt;
The problem is that you are confusing list and formatted inputs. You never use informats with list input!&lt;BR /&gt;
&lt;BR /&gt;
The only exception is by using : when character variable is greater than 8 or numeric variable is non-standard. &lt;BR /&gt;
&lt;BR /&gt;
Second, never use format input with free format data. Use it only with fixed field data. From the very beginning you are trying to use format input for reading the free format data.&lt;BR /&gt;
&lt;BR /&gt;
Third, to avoid SAS jumping to next line because of small record length, use TRUNCOVER option in the infile statement.</description>
      <pubDate>Wed, 29 Dec 2010 21:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-statement-informat-question/m-p/52340#M11061</guid>
      <dc:creator>JatinRai</dc:creator>
      <dc:date>2010-12-29T21:36:01Z</dc:date>
    </item>
  </channel>
</rss>

