<?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: How can i use these code to generate output shown in the photo? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408276#M99610</link>
    <description>&lt;P&gt;Thanks everyone for shortlisted my beginner stupid mistakes! But Actually, I am wondering how can I use those data to generate the output in my photo posted in the last post within one data step as&amp;nbsp; I found out it was difficult to finish it within one data step....Can anyone give some insight on how to project desired output into a dataset?&lt;/P&gt;</description>
    <pubDate>Sat, 28 Oct 2017 18:03:53 GMT</pubDate>
    <dc:creator>bimohkc</dc:creator>
    <dc:date>2017-10-28T18:03:53Z</dc:date>
    <item>
      <title>How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408234#M99592</link>
      <description>&lt;P&gt;Data household (drop=HorP_indicator) ;&lt;BR /&gt;Infile&amp;nbsp;datalines dsd ;&lt;BR /&gt;retain Household_identity Type No_of_members;&lt;BR /&gt;input HorP_indicator :$10. @ ;&lt;BR /&gt;if length(HorP_indicator )&amp;gt;1 then do;&lt;BR /&gt;input @1 Household_identity :$10.&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70859"&gt;@12&lt;/a&gt; Type $&lt;BR /&gt;No_of_members&lt;BR /&gt;Member_no&lt;BR /&gt;H_Indicator $&lt;BR /&gt;DOB :date9.&lt;BR /&gt;Gender $&lt;BR /&gt;M_status $&lt;BR /&gt;Edu_level&lt;BR /&gt;E_Status $&lt;BR /&gt;M_Income;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;input&lt;BR /&gt;@1 Member_no&lt;BR /&gt;H_Indicator $&lt;BR /&gt;DOB :date9.&lt;BR /&gt;Gender $&lt;BR /&gt;M_status $&lt;BR /&gt;Edu_level&lt;BR /&gt;E_Status $&lt;BR /&gt;M_Income ;&lt;BR /&gt;end;&lt;BR /&gt;format DOB date9.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A123456789,A,3&lt;BR /&gt;1,Y,15Feb1960,M,M,3,FT,55000&lt;BR /&gt;2,N,3Jun1965,F,M,3,UE,0&lt;BR /&gt;3,N,24Jan1988,M,S,2,NA,3000&lt;BR /&gt;A135790234,B,1&lt;BR /&gt;1,Y,19Oct1944,F,D,0,NA,3000&lt;BR /&gt;B234523456,A,2&lt;BR /&gt;1,Y,30Jun1978,F,M,1,PT,4000&lt;BR /&gt;2,N,21May1975,M,M,2,FT,30000&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt=".....jpg" style="width: 595px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16272i3E2BC7667D8959E3/image-size/large?v=v2&amp;amp;px=999" role="button" title=".....jpg" alt=".....jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 12:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408234#M99592</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T12:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408236#M99593</link>
      <description>&lt;P&gt;The following step reads the datalines and creates one observation for each row in the details part of your data. Normal group-processing should be sufficient to create the required output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length
      Household_identity $ 10
      Type $ 1
      No_of_members 8
      
      Member_no 8
      H_Indicator $ 1
      DOB 8
      Gender $ 1
      M_status $ 1
      Edu_level 8
      E_Status $ 2
      M_Income 8;     
   ;
   
   informat dob date9.;
   format dob date9.;
   
   retain Household_identity Type No_of_members;
   
   infile datalines delimiter=",";
   input @;
   
   if countc(_infile_, ',') = 2 then do;
      input Household_identity Type No_of_members;
   end;
   else do;
      input Member_no
         H_Indicator
         DOB
         Gender 
         M_status
         Edu_level
         E_Status
         M_Income
      ;
      output;
   end;
   
datalines;
A123456789,A,3
1,Y,15Feb1960,M,M,3,FT,55000
2,N,3Jun1965,F,M,3,UE,0
3,N,24Jan1988,M,S,2,NA,3000
A135790234,B,1
1,Y,19Oct1944,F,D,0,NA,3000
B234523456,A,2
1,Y,30Jun1978,F,M,1,PT,4000
2,N,21May1975,M,M,2,FT,30000
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Oct 2017 13:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408236#M99593</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-10-28T13:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408247#M99595</link>
      <description>&lt;P&gt;&amp;nbsp;Thank for your editing and advice.but in fact, can you provide the code that those data can be shown similar to the photo for reference?&amp;nbsp; since I didn't know how to integrate the data into one observation per header record&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 14:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408247#M99595</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T14:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408254#M99597</link>
      <description>&lt;P&gt;Data household (drop=HorP_indicator) ;&lt;BR /&gt;Infile datalines dsd ;&lt;BR /&gt;retain Household_identity Type No_of_members;&lt;BR /&gt;input HorP_indicator :$10. @ ;&lt;BR /&gt;if length(HorP_indicator )&amp;gt;1 then do;&lt;BR /&gt;input @1 Household_identity :$10.&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70859"&gt;@12&lt;/a&gt; Type $&lt;BR /&gt;No_of_members;&lt;BR /&gt; *Member_no&lt;BR /&gt;H_Indicator $&lt;BR /&gt;DOB :date9.&lt;BR /&gt;Gender $&lt;BR /&gt;M_status $&lt;BR /&gt;Edu_level&lt;BR /&gt;E_Status $&lt;BR /&gt;M_Income;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;input&lt;BR /&gt;@1 Member_no&lt;BR /&gt;H_Indicator $&lt;BR /&gt;DOB :date9.&lt;BR /&gt;Gender $&lt;BR /&gt;M_status $&lt;BR /&gt;Edu_level&lt;BR /&gt;E_Status $&lt;BR /&gt;M_Income ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;format DOB date9.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;BR /&gt;A123456789,A,3&lt;BR /&gt;1,Y,15Feb1960,M,M,3,FT,55000&lt;BR /&gt;2,N,3Jun1965,F,M,3,UE,0 &lt;BR /&gt;3,N,24Jan1988,M,S,2,NA,3000&lt;BR /&gt;A135790234,B,1&lt;BR /&gt;1,Y,19Oct1944,F,D,0,NA,3000&lt;BR /&gt;B234523456,A,2&lt;BR /&gt;1,Y,30Jun1978,F,M,1,PT,4000&lt;BR /&gt;2,N,21May1975,M,M,2,FT,30000&lt;BR /&gt;proc print; run;&lt;BR /&gt;/* summary */;&lt;BR /&gt;data want; set household; by household_identity;&lt;BR /&gt;if first.household_identity then age+intck('year',dob,today())-12;&lt;BR /&gt;if e_status in ('FT','PT') then employed+1;&lt;BR /&gt;income+M_income;&lt;BR /&gt;if gender='M' then males+1; else females+1;&lt;BR /&gt;if last.household_identity then do; income=income/no_of_members;&lt;BR /&gt; output; employed=0; income=0; males=0; females=0; age=0;&lt;BR /&gt;end;&lt;BR /&gt;keep type males females age employed income household_identity;&lt;BR /&gt;proc print label split='*'; id household_identity type &lt;BR /&gt; males females employed age income; &lt;BR /&gt; label males='number of* male members' &lt;BR /&gt; females='number of*female members' age='age of *householder'&lt;BR /&gt; income='average*household*income'; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 15:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408254#M99597</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2017-10-28T15:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408257#M99599</link>
      <description>&lt;P&gt;thanks for the solution! Instead of just adding a new data step, is it possible to output my desired output in one data step? sorry for any inconvenience as I am a SAS beginner&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 15:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408257#M99599</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T15:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408262#M99602</link>
      <description>&lt;P&gt;It could be done in one data step in SAS but there are several reasons why 2 data steps are better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data step 1 is not just inputting a flat file, it is flattening a hierarchical file with 2 different record types. Data step 2 uses the&lt;U&gt; BY&lt;/U&gt; statement with &lt;U&gt;last. feature&lt;/U&gt; that tells we are on the last record of this household.&amp;nbsp; The by statement is not valid after the infile statement. So to put the logic to detect last household &amp;nbsp; in the first data step would complicate it unnecessarily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In programming world there is maintenance. Either you or your peer will need to update this program and keeping the functions of flattening the hierarchical file and summarizing the results in different data steps keeps the logic&amp;nbsp; straight forward and makes maintenance easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could be done but would require lots more logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 16:21:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408262#M99602</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2017-10-28T16:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408266#M99604</link>
      <description>&lt;P&gt;Sorry for the inconvenience caused. Actually, your solution really helps me a lot. However, As I am now doing an assignment that requires me to read the above-shown in-stream data within one data step, the alternative of one data step is more suitable for my assignment requirement. Therefore, can you provide some insight or some example/crucial data step that I need to notice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are my assignment details:&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="Page-wrapper"&gt;&lt;DIV class="Page PageComponent"&gt;&lt;DIV class="Draw"&gt;&lt;DIV class="TextLayer-container"&gt;&lt;DIV class="textLayer"&gt;&lt;DIV class="textLayer--absolute"&gt;Suppose the raw data file SURVEY.TXT (data set is not available) in ‘d:\Temp’ folder&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;contains the result of a recent household survey. The data file is hierarchical in&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;structure, consists of a header record for a household and followed by one detail&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;record for each member of the household. For example, a household with 3&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;members will have 3 detailed records exactly. There is no missing value in the data&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;file. Data values are separated by commas and they are arranged in the order of the&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;following variables:&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="PDFAnnotationLayer-container"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="Page-wrapper"&gt;&lt;DIV class="Page PageComponent"&gt;&lt;DIV class="Page-inner"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="Draw"&gt;&lt;DIV class="PageAnnotations"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="TextLayer-container"&gt;&lt;DIV class="textLayer"&gt;&lt;DIV class="textLayer--absolute"&gt;Header record:&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Variable&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Format&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Household identity&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Exactly 10 characters&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Type of housing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Character ‘A’ for private, and ‘B’ for public&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Number of members in the&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Standard numeric&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;household&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Detail record:&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Variable&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Format&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Member number of the&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;household&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Standard numeric&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Householder indicator&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Character ‘Y’ for yes, and ‘N’ for no&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Date of birth&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;ddmonyyyy&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Gender&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Character ‘F’ for female, and ‘M’ for male&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Marital status&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Character ‘M’ for married, ‘S’ for single, and&amp;nbsp; &amp;nbsp;‘D’ for divorced&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Achieved education level&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Standard numeric with 0 for none, 1 for&amp;nbsp; primary, 2 for secondary, 3 for tertiary&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Employment status&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Characters ‘FT’ for full time, ‘PT’ for part time,‘UE’ for employed, and ‘NA’ for not applicable&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Monthly income&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Standard numeric&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;The first few records of the data file are displayed below:&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Write a DATA step that reads the records from SURVEY.TXT and creates a SAS&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;data set that contains only one observation for each household regardless of the&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;number of members in the household. The created data set must contain only the&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;following variables but not necessary in the given order: household identity, type of&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;housing, number of male members (0 for none), number of female members (0 for&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;none), number of members are working (with either full time or part time job; 0 for&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;none), age of the householder as on 31 of December 2008 rounded to the nearest&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;half year, and average household income rounded to 2 decimal places.&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;The first few observations of the created data set are shown below for reference:&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt=".....jpg" style="width: 595px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16273iE25D771832027135/image-size/large?v=v2&amp;amp;px=999" role="button" title=".....jpg" alt=".....jpg" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="PDFAnnotationLayer-container"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="Page-wrapper"&gt;&lt;DIV class="Page PageComponent"&gt;&lt;DIV class="Page-inner"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="Draw"&gt;&lt;DIV class="PageAnnotations"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="TextLayer-container"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 28 Oct 2017 16:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408266#M99604</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T16:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408268#M99605</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174302"&gt;@bimohkc&lt;/a&gt; wrote:&lt;BR /&gt;...
&lt;DIV&gt;
&lt;DIV class="Page-wrapper"&gt;
&lt;DIV class="Page PageComponent"&gt;
&lt;DIV class="Draw"&gt;
&lt;DIV class="TextLayer-container"&gt;
&lt;DIV class="textLayer"&gt;
&lt;DIV class="textLayer--absolute"&gt;consists of a header record for a household and followed by one detail record for each member of the household.&lt;/DIV&gt;
&lt;DIV class="textLayer--absolute"&gt;For example, a household with 3 members will have 3 detailed records exactly. There is no missing value in the data&lt;/DIV&gt;
&lt;DIV class="textLayer--absolute"&gt;file.&lt;/DIV&gt;
&lt;DIV class="textLayer--absolute"&gt;...&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="PDFAnnotationLayer-container"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is normally a simple exercise. Use RETAIN statement to keep the values you read from the HOUSEHOLD record. Use OUTPUT statement to only write an observations when you are reading a DETAIL record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question does not provide any information on how you are supposed to tell the difference between the HOUSEHOLD and DETAIL records.&amp;nbsp; Is there another field that has that information? Or a COUNT on the HOUSEHOLD record that lets you know how many DETAIL record will follow?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 17:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408268#M99605</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-28T17:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408272#M99608</link>
      <description>&lt;P&gt;Don't post code/data/logs into the main window. Use the icons, {i} or SAS Running Man, on the menu bar to open a pop-up window to paste/edit code.&lt;/P&gt;
&lt;P&gt;Here are some hints for reading a delimited file. DEFINE your variables before using them in statement like INPUT, FORMAT, INFORMAT or assignment.&amp;nbsp; Attach any required informats and/or formats to the variables. Then you can just use list mode on your INPUT statement(s).&amp;nbsp; If you define the variables in the order that appear in the source file then you can even use positional variable lists in your INPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you assume you can trust the number of members field then you do not need to use RETAIN since you can read all members of the household in one data step loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile cards dsd truncover ;
  length Household_identity $10 Type $8 No_of_members 8
         Member_no 8 H_Indicator $8 DOB 8 Gender $1 M_status $8
         Edu_level 8 E_Status $8 M_Income 8
  ;
  informat DOB date. ;
  format DOB date9.;
  input Household_identity -- No_of_members ;
  do _n_=1 to No_of_members ;
     input Member_no -- M_income ;
     output;
  end;
cards;
A123456789,A,3
1,Y,15Feb1960,M,M,3,FT,55000
2,N,3Jun1965,F,M,3,UE,0
3,N,24Jan1988,M,S,2,NA,3000
A135790234,B,1
1,Y,19Oct1944,F,D,0,NA,3000
B234523456,A,2
1,Y,30Jun1978,F,M,1,PT,4000
2,N,21May1975,M,M,2,FT,30000
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 18:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408272#M99608</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-28T18:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408273#M99609</link>
      <description>&lt;P&gt;What means the difference between household record and detail record?&lt;/P&gt;&lt;P&gt;The data has been listed in my previous post and listed as an in-stream data. Thanks for helping!&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 17:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408273#M99609</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T17:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408276#M99610</link>
      <description>&lt;P&gt;Thanks everyone for shortlisted my beginner stupid mistakes! But Actually, I am wondering how can I use those data to generate the output in my photo posted in the last post within one data step as&amp;nbsp; I found out it was difficult to finish it within one data step....Can anyone give some insight on how to project desired output into a dataset?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 18:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408276#M99610</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T18:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408284#M99614</link>
      <description>&lt;P&gt;Do you really need to use a data step or can you use other SAS procedure(s) to produce the report?&lt;/P&gt;
&lt;P&gt;Are you sure you are supposed to generate a dataset or do you just need to reproduce the report?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each column in the report you should first figure out what it represents.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;How would you get that value from the dataset?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Is it just a copy of an existing variable?&lt;/LI&gt;
&lt;LI&gt;is it derived somehow?&amp;nbsp;
&lt;UL&gt;
&lt;LI&gt;What is the definition of the derivation?&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What did you try?&amp;nbsp; How did it not meet your needs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Don't generate the report in the same step that creates the data from the delimited file, that is just silly. That would only be a useful exercise if you already knew how to read the data and how to produce the report with a data step and wanted to learn how to streamline the process because you were working with extremely large data files where two passes through the data would take a extreme amount of time. Even then you could just code the read step as a data step view and then you could code two steps but only pass through the source once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 18:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408284#M99614</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-28T18:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408286#M99615</link>
      <description>&lt;P&gt;Since there is a requirement&amp;nbsp;of 'Write a Data step', it means I can only generate this dataset by using the following data (which is same as the previous post)&lt;/P&gt;&lt;P&gt;A123456789,A,3&lt;BR /&gt;1,Y,15Feb1960,M,M,3,FT,55000&lt;BR /&gt;2,N,3Jun1965,F,M,3,UE,0&lt;BR /&gt;3,N,24Jan1988,M,S,2,NA,3000&lt;BR /&gt;A135790234,B,1&lt;BR /&gt;1,Y,19Oct1944,F,D,0,NA,3000&lt;BR /&gt;B234523456,A,2&lt;BR /&gt;1,Y,30Jun1978,F,M,1,PT,4000&lt;BR /&gt;2,N,21May1975,M,M,2,FT,30000&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt=".....jpg" style="width: 595px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16274i43EC7E46E28DE13A/image-size/large?v=v2&amp;amp;px=999" role="button" title=".....jpg" alt=".....jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I know it is silly, but i am curious how can this be done in the same dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 18:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408286#M99615</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T18:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408292#M99619</link>
      <description>&lt;P&gt;Arrrr.... Since i misunderstood the question, your solution is the best fit for my purpose !!!!!! Anyway, thanks for helping me,everyone!&lt;/P&gt;</description>
      <pubDate>Sat, 28 Oct 2017 19:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408292#M99619</guid>
      <dc:creator>bimohkc</dc:creator>
      <dc:date>2017-10-28T19:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can i use these code to generate output shown in the photo?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408331#M99639</link>
      <description>&lt;PRE&gt;

data want ;
  infile cards dsd truncover ;
length  a b c $ 20;
retain  a b c ;
input aa : $20. @;
if anyalpha(aa)=1 then do;
  a=aa;
  input b : $20. c : $20.;
end;
else do;
 x1=aa;
 input (x2-x8) (: $20.);
 output;
end;
drop aa;
cards;
A123456789,A,3
1,Y,15Feb1960,M,M,3,FT,55000
2,N,3Jun1965,F,M,3,UE,0
3,N,24Jan1988,M,S,2,NA,3000
A135790234,B,1
1,Y,19Oct1944,F,D,0,NA,3000
B234523456,A,2
1,Y,30Jun1978,F,M,1,PT,4000
2,N,21May1975,M,M,2,FT,30000
;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Oct 2017 11:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-i-use-these-code-to-generate-output-shown-in-the-photo/m-p/408331#M99639</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-29T11:32:41Z</dc:date>
    </item>
  </channel>
</rss>

