<?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: Conditional Input from Raw Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/514193#M138643</link>
    <description>&lt;P&gt;Though solution is already selected, please find attached alternative code debugged and fixed&lt;/P&gt;
&lt;P&gt;with hope you find some interest in it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   length father  $10 mother  $10 child $10 tst $3
          address $40; /* addapt length to max expected */
   retain father mother address no_of_childs;
   infile datalines truncover;
   input a_line $80.; 
   
   /* check is there an address */
   tst = scan(a_line,3);
   if tst ne ' ' then do;
      if _N_ &amp;gt; 1 then do; 
	 if no_of_childs = 0 then do;
	    child= ' ';
	    child_age = .;
	    output;
        end;
     end;
     a_line = compbl(a_line);
     father = scan(a_line,1);
     mother = scan(a_line,2);
     add_start = index(a_line, scan(a_line, 3));
     address = substr(a_line, add_start);
     no_of_childs = 0;
     return;
   end;
   child = scan(a_line,1);
   child_age = scan(a_line,2);
   output;
   no_of_childs +1;
    
   drop a_line no_of_childs add_start;
datalines;
Harry    Mary      123 Vermont Ave.
Joe      3
Lisa     2
Felix    Laura     6 Baltic Drive
Karen    12
Thomas   Felicia   424 Suffolk place
Edward   Bella     666 Vampire Lane
Jeff     9
Jared    7
Tim      11
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Nov 2018 05:55:19 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-11-18T05:55:19Z</dc:date>
    <item>
      <title>Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513710#M138443</link>
      <description>&lt;P&gt;&lt;FONT face="andale mono,times"&gt;I have a raw data file that needs to be read into a dataset.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;it looks like this:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;----+----1----+----2----+----3----+----4----+----5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;Harry&amp;nbsp; &amp;nbsp; Mary&amp;nbsp; &amp;nbsp; &amp;nbsp; 123 Vermont Ave.&lt;BR /&gt;Joe&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;Lisa&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;Felix&amp;nbsp; &amp;nbsp; Laura&amp;nbsp; &amp;nbsp; &amp;nbsp;6 Baltic Drive&lt;BR /&gt;Karen&amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;Thomas&amp;nbsp; &amp;nbsp;Felicia&amp;nbsp; &amp;nbsp;424 Suffolk place&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp;Bella&amp;nbsp; &amp;nbsp; &amp;nbsp;666 Vampire Lane&lt;BR /&gt;Jeff&amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;BR /&gt;Jared&amp;nbsp; &amp;nbsp; 7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;Tim&amp;nbsp; &amp;nbsp; &amp;nbsp; 11&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;The variables are &lt;STRONG&gt;Father, Mother, Address&lt;/STRONG&gt; followed by &lt;STRONG&gt;Child&lt;/STRONG&gt; (if any) and &lt;STRONG&gt;Child&amp;nbsp;Age&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;I need to create a dataset that will have one observation per child with repeating Father, Mother and Address information. If no children then Child and age value should be blank. Please Help .. Thanks&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;Desired Result would look like this:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;Father&amp;nbsp; &amp;nbsp;Mother&amp;nbsp; &amp;nbsp; Address&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Child&amp;nbsp; &amp;nbsp; Age&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;---------------------------------------------------&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;Harry&amp;nbsp; &amp;nbsp; Mary&amp;nbsp; &amp;nbsp; &amp;nbsp; 123 Vermont Ave.&amp;nbsp; &amp;nbsp; Joe&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;Harry&amp;nbsp; &amp;nbsp; Mary&amp;nbsp; &amp;nbsp; &amp;nbsp; 123 Vermont Ave.&amp;nbsp; &amp;nbsp; Lisa&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;Felix&amp;nbsp; &amp;nbsp; Laura&amp;nbsp; &amp;nbsp; &amp;nbsp;6 Baltic Drive&amp;nbsp; &amp;nbsp; &amp;nbsp; Karen&amp;nbsp; &amp;nbsp; 12&lt;BR /&gt;Thomas&amp;nbsp; &amp;nbsp;Felicia&amp;nbsp; &amp;nbsp;424 Suffolk place&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp;Bella&amp;nbsp; &amp;nbsp; &amp;nbsp;666 Vampire Lane&amp;nbsp; &amp;nbsp;&amp;nbsp;Jeff&amp;nbsp; &amp;nbsp; &amp;nbsp;9&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp;Bella&amp;nbsp; &amp;nbsp; &amp;nbsp;666 Vampire Lane&amp;nbsp; &amp;nbsp; Jared&amp;nbsp; &amp;nbsp; 7&lt;BR /&gt;Edward&amp;nbsp; &amp;nbsp;Bella&amp;nbsp; &amp;nbsp; &amp;nbsp;666 Vampire Lane&amp;nbsp; &amp;nbsp; Tim&amp;nbsp; &amp;nbsp; &amp;nbsp; 11&lt;BR /&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="andale mono,times"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 10:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513710#M138443</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-16T10:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513721#M138449</link>
      <description>&lt;P&gt;Is this a .txt file?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 23:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513721#M138449</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-15T23:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513727#M138452</link>
      <description>yeah ... its a dat file ... i put the ruler up there just for convenience .. its not part of the file</description>
      <pubDate>Thu, 15 Nov 2018 23:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513727#M138452</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-15T23:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513835#M138509</link>
      <description>&lt;P&gt;Assuming you have no delimiters between variables and&lt;/P&gt;
&lt;P&gt;each name contains one string only without blanks embedded&lt;/P&gt;
&lt;P&gt;then try next code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   length father $10 mother $10 address $40; /* addapt length to max expected */
   retain father mother address no_of_childs;
   infile datalines;
   input a_line $80.
   
   /* check is there an address */
   if scan(a_line,3) ne ' ' then do;
      if _N_ &amp;gt; 1 then do;   
	     if no_of_childs = 0 then do;
		    child= ' ';
			child_age = .;
			output;
	     end;
         a_line = compbl(a_line);
         father = scan(a_line,1);
	     mother = scan(a_line,2);
	     add_start = index(a_line, scan(a_line, 3));
	     address = substr(a_line, add_start);
	     no_of_childs = 0;
	  end;
   end;
   else do;
      input child $ child_age;
	  output;
	  no_of_childs +1;
   end;
datalines;
Harry    Mary      123 Vermont Ave.
Joe      3
Lisa     2
Felix    Laura     6 Baltic Drive
Karen    12
Thomas   Felicia   424 Suffolk place
Edward   Bella     666 Vampire Lane
Jeff     9
Jared    7
Tim      11
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 10:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513835#M138509</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-16T10:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513842#M138510</link>
      <description>&lt;P&gt;Hi Shmuel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran your program verbatim (had to add the ";" for first input statement) ... sorry, but not getting the required result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have edited the initial question text to include the desired result ..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 11:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513842#M138510</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-16T11:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513846#M138512</link>
      <description>&lt;P&gt;How about this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  infile cards truncover eof=done;                                                                                                      
  input @1 father $9. mother $10. address $40.;                                                                                         
  do _N_=1 by 1 until(0);                                                                                                               
    input child $9. age ?? 3.0 @@;                                                                                                      
    if missing(age) then leave;                                                                                                         
    output;                                                                                                                             
    input;                                                                                                                              
    end;                                                                                                                                
  done: /* This is to avoid the "missing card" message in log */                                                                        
  if _N_=1 then do;  /* output when no children read */                                                                                 
    call missing(Child);  /* Father variable has been read as Child */                                                                                                              
    output;                                                                                                                             
    end;                                                                                                                                
cards;                                                                                                                                  
Harry    Mary      123 Vermont Ave.                                                                                                     
Joe      3                                                                                                                              
Lisa     2                                                                                                                              
Felix    Laura     6 Baltic Drive                                                                                                       
Karen    12                                                                                                                             
Thomas   Felicia   424 Suffolk place                                                                                                    
Edward   Bella     666 Vampire Lane                                                                                                     
Jeff     9                                                                                                                              
Jared    7                                                                                                                              
Tim      11                                                                                                                             
;                                                                                                                                       
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 11:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513846#M138512</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-11-16T11:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513848#M138513</link>
      <description>can you please elaborate on what this line does ??&lt;BR /&gt;"" do _N_=1 by 1 until(0); ""&lt;BR /&gt;This seems to be the kicker in the solution but i cant understand the logic&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Nov 2018 11:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513848#M138513</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-16T11:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513850#M138515</link>
      <description>&lt;P&gt;Sorry, I overdid that a bit. "do _N_=1 by 1;" is enough. It is just that I started out with "do until(0);" (meaning "do forever", or at least until you reach a LEAVE or DELETE statement), but then I found I that I needed the loop counter (_N_) to identify couples with no children. And I forgot to remove the "until(0)" bit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"do _N_=1 by 1;" means the same, but with a counter, like "do _N_=1 to infinity;".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your infile is a real file, and not a Cards statement, the DO UNTIL construct can be used like this (CARDS statement does not accept the END= option):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  infile &amp;lt;filename here!&amp;gt; truncover end=done;                                                                                                    
  input @1 father $9. mother $10. address $40.;                                                                                         
  do _N_=1 by 1 until(done);                                                                                                            
    input child $9. age ?? 3.0 @@;                                                                                                      
    if missing(age) then leave;                                                                                                         
    output;                                                                                                                             
    input;                                                                                                                              
    end;                                                                                                                                
  if _N_=1 then do;  /* output when no children read */                                                                                 
    call missing(Child);                                                                                                                
    output;                                                                                                                             
    end;                                                                                                                                
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which will make the program a little bit simpler.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 11:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513850#M138515</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-11-16T11:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513856#M138516</link>
      <description>Got it ...&lt;BR /&gt;thank you very much !!!&lt;BR /&gt;you da man !!!</description>
      <pubDate>Fri, 16 Nov 2018 12:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513856#M138516</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-16T12:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513861#M138517</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
input;
length Father   Mother    Address $ 100;
retain Father   Mother    Address ;
temp=scan(_infile_,2,' ');
if not missing(temp) and notdigit(strip(temp)) then do;
Father=scan(_infile_,1,' ');   
Mother=scan(_infile_,2,' ');
call scan(_infile_,2,p,l,' ');
Address=left(substr(_infile_,p+l));
end; 
else do;
Child=scan(_infile_,1,' ');  
Age=scan(_infile_,2,' '); 
end;
drop temp p l;
cards;                                                                                                                                  
Harry    Mary      123 Vermont Ave.                                                                                                     
Joe      3                                                                                                                              
Lisa     2                                                                                                                              
Felix    Laura     6 Baltic Drive                                                                                                       
Karen    12                                                                                                                             
Thomas   Felicia   424 Suffolk place                                                                                                    
Edward   Bella     666 Vampire Lane                                                                                                     
Jeff     9                                                                                                                              
Jared    7                                                                                                                              
Tim      11                                                                                                                             
;                                                                                                                                       
run;
data final_want;
 set want;
 by Father   Mother    Address notsorted;
 if missing(child) and not (first.Address and last.Address) then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 13:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/513861#M138517</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-11-16T13:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/514193#M138643</link>
      <description>&lt;P&gt;Though solution is already selected, please find attached alternative code debugged and fixed&lt;/P&gt;
&lt;P&gt;with hope you find some interest in it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   length father  $10 mother  $10 child $10 tst $3
          address $40; /* addapt length to max expected */
   retain father mother address no_of_childs;
   infile datalines truncover;
   input a_line $80.; 
   
   /* check is there an address */
   tst = scan(a_line,3);
   if tst ne ' ' then do;
      if _N_ &amp;gt; 1 then do; 
	 if no_of_childs = 0 then do;
	    child= ' ';
	    child_age = .;
	    output;
        end;
     end;
     a_line = compbl(a_line);
     father = scan(a_line,1);
     mother = scan(a_line,2);
     add_start = index(a_line, scan(a_line, 3));
     address = substr(a_line, add_start);
     no_of_childs = 0;
     return;
   end;
   child = scan(a_line,1);
   child_age = scan(a_line,2);
   output;
   no_of_childs +1;
    
   drop a_line no_of_childs add_start;
datalines;
Harry    Mary      123 Vermont Ave.
Joe      3
Lisa     2
Felix    Laura     6 Baltic Drive
Karen    12
Thomas   Felicia   424 Suffolk place
Edward   Bella     666 Vampire Lane
Jeff     9
Jared    7
Tim      11
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2018 05:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/514193#M138643</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-11-18T05:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Input from Raw Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/515399#M139044</link>
      <description>yessir !! that did it too .. thanks</description>
      <pubDate>Thu, 22 Nov 2018 16:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Input-from-Raw-Data/m-p/515399#M139044</guid>
      <dc:creator>jfaruqui</dc:creator>
      <dc:date>2018-11-22T16:38:33Z</dc:date>
    </item>
  </channel>
</rss>

