<?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: get the the array elements in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82410#M17787</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is usually a bad idea to take data from a powerful data base object like a SAS data set and put those values into an object which by comparison one might consider useless.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Aug 2012 17:02:58 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2012-08-02T17:02:58Z</dc:date>
    <item>
      <title>get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82405#M17782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;My intention is to load data set in an array and to use the array in a macro.&lt;/P&gt;&lt;P&gt;The first step is trivial. The second setup i found it in a document it creates an array.&amp;nbsp; In the third step i can read array elements with %put test=&amp;amp;disease_1 etc.&lt;/P&gt;&lt;P&gt;But i must use it in the following wise, so that i don't have to write it manually like &amp;amp;disease_2. i want to change it to&amp;nbsp; &amp;amp;disease_x and x is a counter variable. Like following try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let x=3;&lt;/P&gt;&lt;P&gt;%put test=cats("&amp;amp;disease_",x);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; If you have any other solution to fill array with dataset &lt;/P&gt;&lt;P&gt;elements, you are also welcome. &lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;Serdar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* 1-fill the data set*/&lt;/P&gt;&lt;P&gt;data work.myspace;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input varname $;&lt;/P&gt;&lt;P&gt;DATALINES;&lt;/P&gt;&lt;P&gt;0+&lt;/P&gt;&lt;P&gt;0-&lt;/P&gt;&lt;P&gt;A+&lt;/P&gt;&lt;P&gt;A-&lt;/P&gt;&lt;P&gt;AB+&lt;/P&gt;&lt;P&gt;AB-&lt;/P&gt;&lt;P&gt;B+&lt;/P&gt;&lt;P&gt;B-&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; /* 2- create an array with the elements from data set*/&lt;/P&gt;&lt;P&gt;data myset; Set myspace;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; call symputx (cats("disease_",_N_), varname);&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* 3- Using*/&lt;/P&gt;&lt;P&gt;%put test=&amp;amp;disease_1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 15:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82405#M17782</guid>
      <dc:creator>paul_1</dc:creator>
      <dc:date>2012-08-02T15:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82406#M17783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You mention an array, but you never create one.&amp;nbsp; How do you want to use the macros that you created?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 16:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82406#M17783</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-02T16:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82407#M17784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur,&lt;/P&gt;&lt;P&gt;thank you for very quich feedback.&lt;/P&gt;&lt;P&gt;i found the code in page 3-4 of the document &lt;A href="http://www.nesug.org/proceedings/nesug07/cc/cc27.pdf"&gt;http://www.nesug.org/proceedings/nesug07/cc/cc27.pdf&lt;/A&gt; &lt;/P&gt;&lt;P&gt;i think, what i've created&amp;nbsp; macro variables at the top. But i would be ok for my problem, if i get also them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i change the step 2 into (without retain): &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data myset; Set myspace;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length my_array $ 50 ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my_array&amp;nbsp; = catx (' ', &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;my_array &lt;/SPAN&gt;, varname);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;i hope, &lt;/SPAN&gt;so i would create an array. Still I can't get the data as described. And second problem, if i change the data in &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;myspace&lt;/SPAN&gt;, i receive still the old data,&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 16:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82407#M17784</guid>
      <dc:creator>paul_1</dc:creator>
      <dc:date>2012-08-02T16:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82408#M17785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The macro facility doesn't really have arrays, but you can create a macro variable containing a list and then loop over that list. So, instead of creating a data set with the values you want, set up a list:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let disease_list = 0+ 0- A+ A- AB+ AB- B+ B-;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and then in the context of a macro, you can loop through the list:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO loop_thru_list;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to 8;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let disease&amp;amp;i = %scan(&amp;amp;disease_list, &amp;amp;i, %str( ));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put disease&amp;amp;i = &amp;amp;&amp;amp;&amp;amp;disease&amp;amp;i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%MEND loop_thru_list;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%loop_thru_list;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way you will get 8 macro variables named disease1 thru disease8.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 16:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82408#M17785</guid>
      <dc:creator>tish</dc:creator>
      <dc:date>2012-08-02T16:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82409#M17786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also just load the value onto one macro variable, say &amp;amp;disease, and then do what you need just for that one, then loop back to do the next one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 16:55:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82409#M17786</guid>
      <dc:creator>tish</dc:creator>
      <dc:date>2012-08-02T16:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82410#M17787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is usually a bad idea to take data from a powerful data base object like a SAS data set and put those values into an object which by comparison one might consider useless.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82410#M17787</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-08-02T17:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82411#M17788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It may be time to describe what you are attempting to accomplish overall. Many people coming from other programming backgrounds see SAS elements as behaving like another program might and often use an approach that can be accomplished much simpler than trying to translate another programming language approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 17:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82411#M17788</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-08-02T17:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82412#M17789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm in agreement with data and ballard.&amp;nbsp; For me, major red flags are going off that you don't need macro.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you post exactly what you want to do, with the caveat being that you can't mention "macro" in that message &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ?&amp;nbsp; Just post a representative sample of your source data and target data, preferably via code using datalines that we can easily paste into SAS and run as is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're just curious how you can move data between a SAS dataset and the macro symbol table, then fine, we can post code to do that.&amp;nbsp; Knowing *when* to do that in a "real" program is another kettle of fish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, I recommend you read Chapter 2 of the Macro documentation (it's quite short), and that you have a solid understanding of how SAS compiles a data step, with an understanding of the difference between compile time and run time processing, and when the macro processor handles macro tokens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 22:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82412#M17789</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2012-08-02T22:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: get the the array elements in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82413#M17790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So the OP's question is how to access an element of a so-called macro array, using an index. Here is a way. HTH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Consolas, Courier New; font-size: 90%; line-height: 1.1;"&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_1 = O+;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_2 = O-;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_3 = A+;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_4 = A-;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_5 = AB+;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_6 = AB-;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_7 = B+;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt; btype_8 = B-;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;%macro&lt;/STRONG&gt;&lt;SPAN&gt; btype(idx);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%if&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;idx &amp;lt; &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;1&lt;/STRONG&gt;&lt;SPAN&gt; or &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN&gt; &amp;lt; &amp;amp;idx &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%then&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%return&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;*;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;amp;&amp;amp;btype_&amp;amp;idx&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;%mend&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; btype;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;*-- check --*;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%put&lt;/SPAN&gt;&lt;SPAN&gt; blood type 1 = %btype(1);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;%put&lt;/SPAN&gt;&lt;SPAN&gt; blood type 3 = %btype(3);&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; %&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;*-- on log&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; blood type 1 = O+&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; blood type 3 = A+&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;&amp;nbsp; --*;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 14:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-the-array-elements-in-a-macro/m-p/82413#M17790</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2012-08-03T14:24:02Z</dc:date>
    </item>
  </channel>
</rss>

