<?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: SAS data step programming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509672#M137044</link>
    <description>&lt;P&gt;Use the DSD option to allow it to properly treat the adjacent delimiters as indicating a missing value. DSD implies DLM=','.&amp;nbsp; You should also add the TRUNCOVER option just in case the actual number of values is less than the number indicated.&lt;/P&gt;
&lt;P&gt;You will need more variables to control the number of values to read.&amp;nbsp; You could drop them if you really don't need them.&amp;nbsp; But if you keep only two variables then you have nothing in the data that stores&amp;nbsp;the original order of the values on the line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Purchase;
  infile 'c:\temp\PurchaseRecords.dat' dsd truncover;
  length id $8;
  input id number_of_visits @;
  do visit_no=1 to number_of_visits;
     input unitpurchased @;
     output;
  end;
  keep id visit_no unitpurchased;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also beware of Microsoft products converting your double quote and single quote characters into “stupid” quotes&lt;/P&gt;</description>
    <pubDate>Thu, 01 Nov 2018 20:11:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-01T20:11:38Z</dc:date>
    <item>
      <title>SAS data step programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509625#M137017</link>
      <description>&lt;P&gt;a&lt;/P&gt;</description>
      <pubDate>Sat, 01 Dec 2018 14:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509625#M137017</guid>
      <dc:creator>kennyA</dc:creator>
      <dc:date>2018-12-01T14:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS data step programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509636#M137027</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Welcome !!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you have to add DSD option in infile statement to read correct data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;infile ‘c:\temp\PurchaseRecords.dat’ dlm=’,’ DSD;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 18:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509636#M137027</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-11-01T18:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS data step programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509645#M137031</link>
      <description>&lt;P&gt;This is an interesting question and requires more than just basic knowledge to solve. If your just starting to lean SAS then these type might little confuse you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"_INFILE_" to read the raw data line and then using do loop the extract the required fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Purchase(DROP=i);
infile 'c:\temp\PurchaseRecords.dat';
input @;
	do i=1 to scan(_infile_,2,','); 
		id=scan(_infile_,1,',');
		unitpurchased=scan(_infile_,i+2,',','m');
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;- &lt;STRONG&gt;input&amp;nbsp;@&amp;nbsp; &lt;/STRONG&gt;holds the line&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;scan(_infile_,2,',')&lt;/STRONG&gt; - Extracting the second field ( C005,&lt;STRONG&gt;3&lt;/STRONG&gt;,15,,39 ) from line will tell how many times the loop is required.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;id=scan(_infile_,1,',') &lt;/STRONG&gt;always the first record, extract first values from the line.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;-unitpurchased= scan(_infile_,i+2,',','m') &lt;/STRONG&gt;reading values from 3,4,5...... based on i value. Here fourth argument&amp;nbsp;'m' for scan() is required for consecutive&amp;nbsp;blanks.&lt;/P&gt;
&lt;P&gt;- &lt;STRONG&gt;output&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 521px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24583i130F973EFCF984BE/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 18:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509645#M137031</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-11-01T18:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS data step programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509672#M137044</link>
      <description>&lt;P&gt;Use the DSD option to allow it to properly treat the adjacent delimiters as indicating a missing value. DSD implies DLM=','.&amp;nbsp; You should also add the TRUNCOVER option just in case the actual number of values is less than the number indicated.&lt;/P&gt;
&lt;P&gt;You will need more variables to control the number of values to read.&amp;nbsp; You could drop them if you really don't need them.&amp;nbsp; But if you keep only two variables then you have nothing in the data that stores&amp;nbsp;the original order of the values on the line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Purchase;
  infile 'c:\temp\PurchaseRecords.dat' dsd truncover;
  length id $8;
  input id number_of_visits @;
  do visit_no=1 to number_of_visits;
     input unitpurchased @;
     output;
  end;
  keep id visit_no unitpurchased;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also beware of Microsoft products converting your double quote and single quote characters into “stupid” quotes&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 20:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509672#M137044</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-01T20:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS data step programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509683#M137050</link>
      <description>&lt;P&gt;One more detail worth learning here.&amp;nbsp; Consider your original INPUT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;input id $8 visit_no @ unitpurchased @;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would guess that your intent is to read 8 characters to get the value for ID.&amp;nbsp; But that's not what the program says.&amp;nbsp; It actually says to take the contents of column 8 (just a single character) as the value of ID.&amp;nbsp; If you want to give instructions that tell SAS to read 8 characters, you need to add a dot:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;input id $8. visit_no @ unitpurchased @;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 20:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-data-step-programming/m-p/509683#M137050</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-01T20:38:29Z</dc:date>
    </item>
  </channel>
</rss>

