<?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: Need Efficient solution for Reading a raw file conditionally? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208592#M267226</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure this is what you are looking for but I do not know how to perform what you are asking while the file is being pulled into SAS.&amp;nbsp; Hopefully someone else comes up with something better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards dsd;&lt;/P&gt;&lt;P&gt;input year code bep_org_code&amp;nbsp;&amp;nbsp; bep_pgm_ele_code&amp;nbsp; tran_pgm_ele_code&amp;nbsp;&amp;nbsp; end_date$ ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2009,10,45,34,234,null&lt;/P&gt;&lt;P&gt;2010,15,45,34,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,23,234,null&lt;/P&gt;&lt;P&gt;2010,15,45,34,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,23,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,13,234,null&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(rename=(year2=year code2=code));&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;retain year2 code2;&lt;/P&gt;&lt;P&gt;if _N_ = 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; year2 = year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; code2 = code;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if _N_ &amp;gt; 1 then do;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; year = year2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; code = code2;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop year code;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Jun 2015 18:50:19 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-06-17T18:50:19Z</dc:date>
    <item>
      <title>Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208590#M267224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need an efficient solution(robust performance) in reading a very large(over 5 million records) comma separated file conditionally.&amp;nbsp; The CSV file looks like the following:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Id,date, name, address. post_code......etc totally 32 variables.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The condition is that values start from the 2nd observation with firstobs=2 as straight forward reading as one would expect, however I first need to read values of two variables from the header row and retain them across all obs.&lt;/P&gt;&lt;P&gt;The logic in my mind is something like:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;if first obs 1 then infile 'mycsvfile' obs=1;&lt;/P&gt;&lt;P&gt;input var1 informat. var2 informat.&lt;/P&gt;&lt;P&gt;else if 2nd obs to EOF then infile 'same csv file'&amp;nbsp; and input all variables with informats&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in essence var1 and var2 will have to read in the beginning and it's value needs to be retained across all iterations until end of file.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your help with the right logic would really mean a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Charlotte&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 17:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208590#M267224</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-06-17T17:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208591#M267225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One way is to set a flag variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; informat var1 informat. var2 informat. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain flag . var1 var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if flag=. then input var1 var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; flag=1; /* after the first read;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input &amp;lt;the rest of the stuff&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop flag;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Other would be to create two datasets, one only ready line 1 for your var1 and 2 the other starting at obs2 then combine the two&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 18:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208591#M267225</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-06-17T18:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208592#M267226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure this is what you are looking for but I do not know how to perform what you are asking while the file is being pulled into SAS.&amp;nbsp; Hopefully someone else comes up with something better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile cards dsd;&lt;/P&gt;&lt;P&gt;input year code bep_org_code&amp;nbsp;&amp;nbsp; bep_pgm_ele_code&amp;nbsp; tran_pgm_ele_code&amp;nbsp;&amp;nbsp; end_date$ ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2009,10,45,34,234,null&lt;/P&gt;&lt;P&gt;2010,15,45,34,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,23,234,null&lt;/P&gt;&lt;P&gt;2010,15,45,34,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,23,234,current&lt;/P&gt;&lt;P&gt;2010,15,45,13,234,null&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(rename=(year2=year code2=code));&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;retain year2 code2;&lt;/P&gt;&lt;P&gt;if _N_ = 1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; year2 = year;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; code2 = code;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if _N_ &amp;gt; 1 then do;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; year = year2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; code = code2;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop year code;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 18:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208592#M267226</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-17T18:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208593#M267227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's one approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;infile "mycsvfile" dsd;&lt;/P&gt;&lt;P&gt;if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input var1 informat. var2 informat.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;retain var1 var2;&lt;/P&gt;&lt;P&gt;input id date name address ...;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm assuming you have all the other pieces you would need ... lengths/informats spelled out appropriately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jun 2015 18:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208593#M267227</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-17T18:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208594#M267228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;, very neat logic. Great! and Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jun 2015 05:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208594#M267228</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-06-20T05:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208595#M267229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A __default_attr="5253" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;, Sorry for the bother, in the code, may i seek a small clarification and tweak that's commented&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;infile "mycsvfile" dsd;&lt;/P&gt;&lt;P&gt;if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input var1 informat. var2 informat.;/* If i want the read the value of Var5, how to skip the 3rd and 4th value and read the value of Var5 correctly?Coz my understanding is clear to read var1 and var2 being the first 2 values and a third value to read happens to be the 5th in the buffer*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;retain var1 var2;&lt;/P&gt;&lt;P&gt;input id date name address ...;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jun 2015 15:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208595#M267229</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-06-22T15:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208596#M267230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Charlotte,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length dummyvar $ 1;&lt;/P&gt;&lt;P&gt;drop dummyvar;&lt;/P&gt;&lt;P&gt;input var1 informat. var2 informat. dummyvar dummyvar var5 informat.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The INPUT statement will keep reading till it finds a delimiter (not stopping just because it read one character of DUMMYVAR).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jun 2015 17:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208596#M267230</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-22T17:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need Efficient solution for Reading a raw file conditionally?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208597#M267231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Sir, I should have guessed it. My apologies for bothering again. Have a nice day&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jun 2015 19:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Efficient-solution-for-Reading-a-raw-file-conditionally/m-p/208597#M267231</guid>
      <dc:creator>CharlotteCain</dc:creator>
      <dc:date>2015-06-22T19:04:57Z</dc:date>
    </item>
  </channel>
</rss>

