<?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: Proper formatting for input statement when creating dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815080#M321725</link>
    <description>&lt;P&gt;Use the colon modifier in front of the formats, or the INPUT will not honor the delimiters.&lt;/P&gt;
&lt;P&gt;Also use date informats for date values, and a character type for IDs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input member_id :$7. first_attr_month :yymmn6. last_attr_month :yymmn6. first_eng_month :yymmn6. treatment :$2. age_group :$5. gender :$1.;
format first_attr_month last_attr_month first_eng_month yymmn6.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 May 2022 19:13:39 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-25T19:13:39Z</dc:date>
    <item>
      <title>Proper formatting for input statement when creating dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815076#M321723</link>
      <description>&lt;P&gt;I'm creating a test dataset. Usually the following input statement works fine, but this time SAS is incorrectly reading my input - it's blending variable values from different columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've checked my syntax in the documentation but can't figure out what's going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mbr_demo_test;
input member_id 7. first_attr_month $6. last_attr_month $6. first_eng_month $6. treatment $2. age_group $5. gender $1.;
datalines;
1234567 201701 202112 . No 70-74 M&lt;BR /&gt;2345678 201907 202009 202001 Y 65-69 F
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 May 2022 18:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815076#M321723</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2022-05-25T18:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proper formatting for input statement when creating dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815079#M321724</link>
      <description>&lt;P&gt;Fixed the problem by removing the variable length values from the input statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mbr_demo_test;
input member_id 7. first_attr_month $ last_attr_month $ first_eng_month $ treatment $ age_group $ gender $;
datalines;
1234567 201701 202112 . No 70-74 M2345678 201907 202009 202001 Y 65-69 F
;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works, although it adds a lot of padding (empty space) to each variable.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 19:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815079#M321724</guid>
      <dc:creator>RobertWF1</dc:creator>
      <dc:date>2022-05-25T19:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proper formatting for input statement when creating dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815080#M321725</link>
      <description>&lt;P&gt;Use the colon modifier in front of the formats, or the INPUT will not honor the delimiters.&lt;/P&gt;
&lt;P&gt;Also use date informats for date values, and a character type for IDs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input member_id :$7. first_attr_month :yymmn6. last_attr_month :yymmn6. first_eng_month :yymmn6. treatment :$2. age_group :$5. gender :$1.;
format first_attr_month last_attr_month first_eng_month yymmn6.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 19:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815080#M321725</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-25T19:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proper formatting for input statement when creating dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815081#M321726</link>
      <description>&lt;P&gt;You also have 13 values in your dataline, but only 7 variables in your INPUT.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 19:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815081#M321726</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-25T19:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proper formatting for input statement when creating dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815122#M321734</link>
      <description>&lt;P&gt;Do you mean that the INPUT statement does not match how the data appears on the line?&lt;/P&gt;
&lt;P&gt;I would agree that they don't match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are using fixed length formats to read the values.&amp;nbsp; So just turn on the ruler line and check whether the values line up with the positions you are reading.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653516387904.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71758iA63585FDB1866983/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1653516387904.png" alt="Tom_0-1653516387904.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So it seem pretty clear there is an issue here.&amp;nbsp; You read the first 7 characters into MEMBER_ID then read the next 6 into FIRST_ATTR_MONTH.&amp;nbsp; But there is a space in the 8th position.&amp;nbsp; So the 6 characters you read are the space and then the first 5 characters of the '201701' string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you seem to have two observations worth of data on one line of data.&lt;/P&gt;
&lt;P&gt;If you want to use fixed position input (formatted input) then align the data to the positions you are reading.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1653516661383.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71759i70459A97B2768840/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1653516661383.png" alt="Tom_1-1653516661383.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Or change the INPUT statement to use LIST mode.&amp;nbsp; In that case make sure there is at least one space between values, no embedded spaces, and no completely empty values (use single period to mark missing values).&lt;/P&gt;
&lt;P&gt;So either add the : prefix on (any needed) informats.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mbr_demo_test;
input member_id first_attr_month :$6. last_attr_month :$6. first_eng_month :$6. treatment :$2. age_group :$5. gender :$1.;
datalines;
1234567 201701 202112      . No 70-74 M
2345678 201907 202009 202001  Y 65-69 F
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just define the variables before using them in the input statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mbr_demo_test;
  length member_id 8 first_attr_month last_attr_month first_eng_month $6 treatment $2 age_group $5 gender $1;
  inpput member_id -- gender;
datalines;
1234567 201701 202112      . No 70-74 M
2345678 201907 202009 202001  Y 65-69 F
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 22:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proper-formatting-for-input-statement-when-creating-dataset/m-p/815122#M321734</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-25T22:15:29Z</dc:date>
    </item>
  </channel>
</rss>

