<?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: Header Preblem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Header-Preblem/m-p/900510#M355894</link>
    <description>&lt;P&gt;The idea here is to read in the HHID and HHTYPE, but retain those values while counting household members, until a new raw data household line is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "trick" here is to read a line of data, but defer reading the HHID and HHTYPE variables.&amp;nbsp; This is done by using the _INFILE_ automatic variable that is generated with every INPUT statement.&amp;nbsp; So the "naked" INPUT statement in the loop below simply generates _INFILE_.&amp;nbsp; When an _INFILE_ with only two comma-separated values is encountered, you know you've finished counting the previous HHID membership.&amp;nbsp; That's when you output the exhausted household, and can identify the incoming household.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'path to your hirarchical file' dlm=',' end=end_of_data ;
  retain hhid '               '  hhtype ' ';
  do mem_count=0 by 1 until (countw(_infile_,',')=2  or end_of_data);
    input;
  end;
  if hhid^=' ' then output;
  hhid=scan(_infile_,1,',');
  hhtype=scan(_infile_,2,',');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 29 Oct 2023 18:14:35 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-10-29T18:14:35Z</dc:date>
    <item>
      <title>Header Preblem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Header-Preblem/m-p/900499#M355888</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;I&lt;/SPAN&gt;&lt;SPAN class=""&gt;t&lt;/SPAN&gt; &lt;SPAN class=""&gt;consists of a header record for a household and&lt;/SPAN&gt; &lt;SPAN class=""&gt;is&lt;/SPAN&gt;&lt;SPAN class=""&gt;immediately&lt;/SPAN&gt; &lt;SPAN class=""&gt;followed by one record&lt;/SPAN&gt; &lt;SPAN class=""&gt;(row)&lt;/SPAN&gt; &lt;SPAN class=""&gt;for each household&lt;/SPAN&gt; &lt;SPAN class=""&gt;member&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;if applicable&lt;/SPAN&gt;&lt;SPAN class=""&gt;. For&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;example, a household&lt;/SPAN&gt; &lt;SPAN class=""&gt;of&lt;/SPAN&gt; &lt;SPAN class=""&gt;three&lt;/SPAN&gt; &lt;SPAN class=""&gt;members will have&lt;/SPAN&gt; &lt;SPAN class=""&gt;three&lt;/SPAN&gt; &lt;SPAN class=""&gt;records exactly&lt;/SPAN&gt; &lt;SPAN class=""&gt;after its header&lt;/SPAN&gt;&lt;SPAN class=""&gt;record&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt; &lt;SPAN class=""&gt;A&lt;/SPAN&gt; &lt;SPAN class=""&gt;household may have no&lt;/SPAN&gt; &lt;SPAN class=""&gt;identified&lt;/SPAN&gt; &lt;SPAN class=""&gt;member at the time of&lt;/SPAN&gt; &lt;SPAN class=""&gt;the&lt;/SPAN&gt; &lt;SPAN class=""&gt;survey. In that case,&lt;/SPAN&gt;&lt;SPAN class=""&gt;the&lt;/SPAN&gt; &lt;SPAN class=""&gt;household&lt;/SPAN&gt; &lt;SPAN class=""&gt;will&lt;/SPAN&gt; &lt;SPAN class=""&gt;have&lt;/SPAN&gt; &lt;SPAN class=""&gt;only a header record in the file.&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;May I ask that how to let the programme know how many&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;record under the Header? Thank a lot!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;A1234567BC012,A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;15/FEB/1980,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Y,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Male,Married,3,FT,55000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;3/JUN/1982,&lt;/SPAN&gt;&lt;SPAN class=""&gt;N,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Female,Married,3,UE,0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;24/JAN/2005,&lt;/SPAN&gt;&lt;SPAN class=""&gt;N,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Male,Unknown,2,NA,0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;D135EG023456789,B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;19/OCT/1950,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Y,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Female,Divorced,0,PT,5000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;X123A567F9,A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;B2345234CC,A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;21/MAY/1975,&lt;/SPAN&gt;&lt;SPAN class=""&gt;N,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Male&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Married,2,FT,30000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;30/JUN/1978,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Y,&lt;/SPAN&gt;&lt;SPAN class=""&gt;Female&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;&lt;SPAN class=""&gt;M&lt;/SPAN&gt;&lt;SPAN class=""&gt;arried&lt;/SPAN&gt;&lt;SPAN class=""&gt;,1,PT,10000&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Oct 2023 15:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Header-Preblem/m-p/900499#M355888</guid>
      <dc:creator>ericykc</dc:creator>
      <dc:date>2023-10-29T15:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Header Preblem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Header-Preblem/m-p/900510#M355894</link>
      <description>&lt;P&gt;The idea here is to read in the HHID and HHTYPE, but retain those values while counting household members, until a new raw data household line is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "trick" here is to read a line of data, but defer reading the HHID and HHTYPE variables.&amp;nbsp; This is done by using the _INFILE_ automatic variable that is generated with every INPUT statement.&amp;nbsp; So the "naked" INPUT statement in the loop below simply generates _INFILE_.&amp;nbsp; When an _INFILE_ with only two comma-separated values is encountered, you know you've finished counting the previous HHID membership.&amp;nbsp; That's when you output the exhausted household, and can identify the incoming household.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'path to your hirarchical file' dlm=',' end=end_of_data ;
  retain hhid '               '  hhtype ' ';
  do mem_count=0 by 1 until (countw(_infile_,',')=2  or end_of_data);
    input;
  end;
  if hhid^=' ' then output;
  hhid=scan(_infile_,1,',');
  hhtype=scan(_infile_,2,',');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Oct 2023 18:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Header-Preblem/m-p/900510#M355894</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-29T18:14:35Z</dc:date>
    </item>
  </channel>
</rss>

