<?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: Using reference data in a sas program in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906703#M358012</link>
    <description>&lt;P&gt;An ARRAY is just a convenient way to reference a series of variables using an index.&amp;nbsp; They only exist for the step where they are defined.&amp;nbsp; Any variables you create using references to elements of an array will exist but the concept of an array will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the DATA generated in the first data step then include that data as input to the second data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I suspect that you just need one data step.&lt;/P&gt;
&lt;P&gt;Lets assume your REFERENCE dataset has 40 observations of a variable named VALUE.&amp;nbsp; And your real data, let's call it HAVE, has a variable named INDEX with values from 1 to 40 and you want to use that to lookup the the right value for REFERENCE.&amp;nbsp; In that case your single data step might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
      array ref [40]  _temporary_;
      do i=1 to 40;
         set reference ;
         ref[i] = value;
      end;
  end;
  set have;
  if index in (1:40) then value=ref[index];
  else value=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Dec 2023 14:15:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-07T14:15:41Z</dc:date>
    <item>
      <title>Using reference data in a sas program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906694#M358009</link>
      <description>&lt;P&gt;I have some&amp;nbsp; reference data that I've imported from a csv file.&lt;/P&gt;&lt;P&gt;Then using a data step 1 - I've then stored them in arrays.&lt;/P&gt;&lt;P&gt;I've then create a new data step 2 based around some transactions using macros but when I try to reference the arrays created in data step 1 it is not recognising them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the best solution to overcome this scenario&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 12:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906694#M358009</guid>
      <dc:creator>Danduke22</dc:creator>
      <dc:date>2023-12-07T12:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using reference data in a sas program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906696#M358010</link>
      <description>&lt;P&gt;Data step #2 does not know about arrays created in data step #1. You would have to define the same arrays in data step #2 in order to work with arrays in data step #2.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 12:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906696#M358010</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-12-07T12:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using reference data in a sas program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906703#M358012</link>
      <description>&lt;P&gt;An ARRAY is just a convenient way to reference a series of variables using an index.&amp;nbsp; They only exist for the step where they are defined.&amp;nbsp; Any variables you create using references to elements of an array will exist but the concept of an array will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the DATA generated in the first data step then include that data as input to the second data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I suspect that you just need one data step.&lt;/P&gt;
&lt;P&gt;Lets assume your REFERENCE dataset has 40 observations of a variable named VALUE.&amp;nbsp; And your real data, let's call it HAVE, has a variable named INDEX with values from 1 to 40 and you want to use that to lookup the the right value for REFERENCE.&amp;nbsp; In that case your single data step might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
      array ref [40]  _temporary_;
      do i=1 to 40;
         set reference ;
         ref[i] = value;
      end;
  end;
  set have;
  if index in (1:40) then value=ref[index];
  else value=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Dec 2023 14:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906703#M358012</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-07T14:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using reference data in a sas program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906707#M358013</link>
      <description>&lt;P&gt;You would need to provide a bit more detail of how this reference data looks like and how you want to use it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS Arrays are just a way to address individual variables within a data step. They don't persist over data step boundaries.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use hash lookups (hash tables) to lookup values over a key.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a data step merge or a SQL join to add reference data to a base table.&lt;/P&gt;
&lt;P&gt;The one thing that you can store permanently are key/value pairs in the form of a SAS format (proc format cntlin= ). Once the format has been created you can use it in any data step and also in procedures.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 14:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906707#M358013</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-07T14:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using reference data in a sas program</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906722#M358020</link>
      <description>&lt;P&gt;Can you provide a small example of HOW you are using the reference data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the "reference" data is used to look up things, example product number to product name, price&amp;nbsp; or description then using that data to make a Format may be more flexible approach than actually combining data sets and manipulation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460563"&gt;@Danduke22&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have some&amp;nbsp; reference data that I've imported from a csv file.&lt;/P&gt;
&lt;P&gt;Then using a data step 1 - I've then stored them in arrays.&lt;/P&gt;
&lt;P&gt;I've then create a new data step 2 based around some transactions using macros but when I try to reference the arrays created in data step 1 it is not recognising them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the best solution to overcome this scenario&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help would be greatly appreciated!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Dec 2023 15:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-reference-data-in-a-sas-program/m-p/906722#M358020</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-07T15:37:59Z</dc:date>
    </item>
  </channel>
</rss>

