<?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: Parsing input file to create two output files in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855985#M37743</link>
    <description>&lt;P&gt;Is the source the TEXT in your first data step? Or do you only have the actual DATASET as the source?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is TEXT then this looks like a simple data step to read.&amp;nbsp; Just use a bare INPUT statement so you can check if the line starts with a hyphen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile text truncover ;
  input @;
  if _infile_ =: '-' then do;
* statements to handle the lines that start with hyphen;
  end;
  else do;
* statements to handle the other lines ;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 27 Jan 2023 15:34:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-27T15:34:17Z</dc:date>
    <item>
      <title>Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855964#M37737</link>
      <description>&lt;P&gt;I'm parsing a file and trying associate the entries there into one of two categories, complex or simple. Then ultimately save those off in separate output files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My test data/script is as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; data have;                                      
     infile cards;                               
     input msg $ 01-80;                          
     cards;                                      
-  23025  110400    LSCHD,LIST=SCHD,JOB=HAWKEYE  
FRED     NDAY=250                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=HOTLIPS  
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=KLINGER  
WILMA     DAY=213                                
FRED      DAY=051                                
FRED      DAY=051                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=BJ       
BARNEY    DAY=213                                
FRED      DAY=051                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=CHARLES 
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025 
;                                               
run;                                            
                                                
data want;                                      
  set have;                                     
    if msg =: '-' then do;                      
       var1 = (substr(msg, 41,08));             
       keep var1;                               
    end;                                        
    else if msg =: 'FRED'    or                 
            msg =: 'WILMA'   or                 
            msg =: 'BARNEY'  then do;           
                file complex;                   
                put @1 var1;                    
            end;                                
    else do;                                    
            file simple;    
            put @1 var1;  
         end;             
                          
    ;                                         &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The lines starting with a dash(-) I use to get var1. If a subsequent line starts with a specific value(fred, Wilma, barney), then var1 gets classified as complex. Otherwise var1 gets classified as simple.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although it indicated that records are written to both files, they are blank records.&lt;/P&gt;&lt;PRE&gt;NOTE: 6 records were written to the file COMPLEX.  
NOTE: 5 records were written to the file SIMPLE.   &lt;/PRE&gt;&lt;P&gt;My Complex file should consist of:&lt;/P&gt;&lt;P&gt;HAWKEYE&lt;/P&gt;&lt;P&gt;KLINGER&lt;/P&gt;&lt;P&gt;BJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the Simple file should consist of :&lt;/P&gt;&lt;P&gt;HOTLIPS&lt;/P&gt;&lt;P&gt;CHARLES&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the assistance.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 14:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855964#M37737</guid>
      <dc:creator>serge68</dc:creator>
      <dc:date>2023-01-27T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855965#M37738</link>
      <description>&lt;P&gt;The way I see it, none of your strings is longer than 40 bytes, so your SUBSTR starting at positiion 41 will only fetch blanks.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 14:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855965#M37738</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-27T14:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855967#M37739</link>
      <description>&lt;P&gt;It really helps if you LOOK AT your data to see what is happening. (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 3&lt;/A&gt;, Know your Data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For all records where NOT msg=:'-' (these are the ones that will potentially be written out, the records that begin with a dash never get to the rest of the code), var1 is always blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1674831250100.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79876i0AA71C932B1A6943/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PaigeMiller_0-1674831250100.png" alt="PaigeMiller_0-1674831250100.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 14:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855967#M37739</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-27T14:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855981#M37740</link>
      <description>&lt;P&gt;Not sure if its how I represented the data here, but the substr does work. Running this finds the entries I'm after there -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;                          
  set have;                         
    if msg =: '-' then do;          
       var1 = (substr(msg, 41,08)); 
       keep var1;                   
    end;                            
                                    
    ;                               
                                    
 proc print data=want;              &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;returns this -&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Obs    var1      
                 
  1    HAWKEYE   
  2              
  3              
  4    HOTLIPS   
  5              
  6    KLINGER   
  7              
  8              
  9              
 10              
 11    BJ        
 12              
 13              
 14              
 15    CHARLES   
 16              &lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855981#M37740</guid>
      <dc:creator>serge68</dc:creator>
      <dc:date>2023-01-27T15:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855982#M37741</link>
      <description>&lt;P&gt;Right, and its probably just my ignorance, but I'm not understanding why that is.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855982#M37741</guid>
      <dc:creator>serge68</dc:creator>
      <dc:date>2023-01-27T15:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855984#M37742</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/100218"&gt;@serge68&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Right, and its probably just my ignorance, but I'm not understanding why that is.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The simple answer is that you wrote code which produces blank VAR1. All records which begin with '-' get var1 computed, records that do not begin with '-' will not have a VAR1 computed and only the records that do not begin with '-' will be sent to the output files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to fix it? This is untested, I don't know if it gets the desired results, but you can test it ... add a RETAIN statement so that the value in VAR1 is carried forward to the next record. First few lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    retain var1;
    set have;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855984#M37742</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-27T15:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855985#M37743</link>
      <description>&lt;P&gt;Is the source the TEXT in your first data step? Or do you only have the actual DATASET as the source?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is TEXT then this looks like a simple data step to read.&amp;nbsp; Just use a bare INPUT statement so you can check if the line starts with a hyphen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile text truncover ;
  input @;
  if _infile_ =: '-' then do;
* statements to handle the lines that start with hyphen;
  end;
  else do;
* statements to handle the other lines ;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jan 2023 15:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855985#M37743</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-27T15:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855994#M37744</link>
      <description>&lt;P&gt;Your rules don't really clearly describe what output should come from&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=KLINGER  
WILMA     DAY=213                                
FRED      DAY=051                                
FRED      DAY=051      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have both WILMA and FRED without reading a new var1. Your rules did not state "first only following" or "last" or some other rule as to&amp;nbsp;exactly which of these triggers the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This matches your desired output for the given example text:&lt;/P&gt;
&lt;PRE&gt; data complex (keep=Var1) simple (keep=var1);                                      
     infile cards truncover; 
     length var1 word $ 15; 
     retain var1;
     input @;                          
     if _infile_ =:'-' then do;
        input @'JOB=' var1;
     end;
     else if not missing(var1) then do;
        word=(scan(_infile_,1));
        if word in ('FRED' 'WILMA' 'BARNEY') then do;
           output complex;
           call missing(var1);
        end;
        else do;
           output simple;
           call missing(var1);
        end;

     end;
     cards;                                      
-  23025  110400    LSCHD,LIST=SCHD,JOB=HAWKEYE  
FRED     NDAY=250                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=HOTLIPS  
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=KLINGER  
WILMA     DAY=213                                
FRED      DAY=051                                
FRED      DAY=051                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=BJ       
BARNEY    DAY=213                                
FRED      DAY=051                                
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025  
-  23025  110400    LSCHD,LIST=SCHD,JOB=CHARLES 
SLIG-00 REQUEST COMPLETED AT 11:04:01 ON 23.025 
;                                               
run;        &lt;/PRE&gt;
&lt;P&gt;The first Infile statement with the @ is there to populate the automatic variable _infile_ which has the current input line.&lt;/P&gt;
&lt;P&gt;If you have not seen it before the =: is "begins with" and the @'text string' on an input statement says&amp;nbsp; "go to the position where the string is and start reading. So there isn't a need to hard code in column count where JOB= occurs.&lt;/P&gt;
&lt;P&gt;This assumes that you want the first value like Fred, Wilma or Barney only to output. Setting the Var1 value to missing after it is written once and then testing to see if a value of the variable is available to write is one way to control how many tests are needed.&lt;/P&gt;
&lt;P&gt;To send output to two different sets you need the names on the Data statement and then an explicit Output &amp;lt;data set name&amp;gt; only writes to that one set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More complex values may need to modify&amp;nbsp; the input statements as your example data all consists of one word. More words will require additional code.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/855994#M37744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-27T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/856001#M37747</link>
      <description>&lt;P&gt;Thanks, the retain is helping.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My complex file looks good.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Though the simple file gets all var1 entries added to it(both those that are simple &amp;amp; complex). Struggling with how to not have the complex entries included there.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 16:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/856001#M37747</guid>
      <dc:creator>serge68</dc:creator>
      <dc:date>2023-01-27T16:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing input file to create two output files</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/856008#M37752</link>
      <description>&lt;P&gt;Awesome. Thanks for this. It looks like what I'm after. Will continue to test here.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2023 16:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-input-file-to-create-two-output-files/m-p/856008#M37752</guid>
      <dc:creator>serge68</dc:creator>
      <dc:date>2023-01-27T16:43:22Z</dc:date>
    </item>
  </channel>
</rss>

