<?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 Input records of data file into specific array elements. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209123#M306796</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sure this must be easy; but I can't figure out how to do it.&lt;/P&gt;&lt;P&gt;I have a data file with several thousand records; 1 record per line. Each record has a variable "i" and a variable "x".&lt;/P&gt;&lt;P&gt;I wish to read the input file, and put "x" into a 1-dimensional array where the array element is identified by "i"; and some values of "i" are missing (e.g., i = 1, 2, 3, 5, 6, 10, ...). &lt;/P&gt;&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Jul 2015 18:34:08 GMT</pubDate>
    <dc:creator>david_fredericton</dc:creator>
    <dc:date>2015-07-22T18:34:08Z</dc:date>
    <item>
      <title>Input records of data file into specific array elements.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209123#M306796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sure this must be easy; but I can't figure out how to do it.&lt;/P&gt;&lt;P&gt;I have a data file with several thousand records; 1 record per line. Each record has a variable "i" and a variable "x".&lt;/P&gt;&lt;P&gt;I wish to read the input file, and put "x" into a 1-dimensional array where the array element is identified by "i"; and some values of "i" are missing (e.g., i = 1, 2, 3, 5, 6, 10, ...). &lt;/P&gt;&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 18:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209123#M306796</guid>
      <dc:creator>david_fredericton</dc:creator>
      <dc:date>2015-07-22T18:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Input records of data file into specific array elements.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209124#M306797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you asking if you can use an array reference in an INPUT statement?&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; ar;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;infile&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;cards&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;missover&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; y[&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;10&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;];&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;do&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;while&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;(&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; i @;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; missing(i) &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; leave;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; input y&lt;I&gt; @;&lt;BR /&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;end&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; i;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;cards&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;10 77 1 44 5 44 2 6 3 8&lt;BR /&gt;1 99 10 99 2 8&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;;;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 19:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209124#M306797</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-07-22T19:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Input records of data file into specific array elements.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209125#M306798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is already a one dimensional array.&lt;/P&gt;&lt;P&gt;Did you want to convert it into a dataset with one observation and N columns?&lt;/P&gt;&lt;P&gt;Did you want to convert it into a dataset with one variable and N rows?&lt;/P&gt;&lt;P&gt;In either case did you want to insert the missing values for the cells not mentioned in the original data?&lt;/P&gt;&lt;P&gt;Do you know the domain of values for I so that you can set the boundaries for this "array"?&amp;nbsp; Or do you want to dynamically determine them from the data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's assume that you DO know the boundaries you can make a dataset with one row and N columns very easily.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp; do until (eof);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; infile 'myfile' end=eof ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; input i x @@ ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; array out x1-x100 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; if 1 &amp;lt;= i &amp;lt;= dim(out) then out(i)=x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; else put 'Invalid value for I. ' i= x= ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;&amp;nbsp; drop i x ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 12pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 19:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209125#M306798</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-07-22T19:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Input records of data file into specific array elements.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209126#M306799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an approach that works when you already have a SAS data set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=have prefix='X' out=want (drop=_name_);&lt;/P&gt;&lt;P&gt;&amp;nbsp; var x;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The results can be different than the other proposed solution in a couple of ways.&amp;nbsp; (1) This program will generate an error if you have two observations with the same X value.&amp;nbsp; It's not clear whether that's a good or a bad outcome, but it's an alternative.&amp;nbsp; And (2) This program will only create the variables that are needed.&amp;nbsp; If there is no observation having i=2, for example, it does not create a variable named X2.&amp;nbsp; Again, you have to choose whether that's good or bad.&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>Thu, 23 Jul 2015 01:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209126#M306799</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-07-23T01:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Input records of data file into specific array elements.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209127#M306800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;&lt;P&gt;It turns out that the suggestion provided by Tom is the most appropriate for my specific situation/application.&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2015 17:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Input-records-of-data-file-into-specific-array-elements/m-p/209127#M306800</guid>
      <dc:creator>david_fredericton</dc:creator>
      <dc:date>2015-07-24T17:45:12Z</dc:date>
    </item>
  </channel>
</rss>

