<?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: Creating multiple macro variables from values of one variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320525#M70619</link>
    <description>&lt;P&gt;You can use SQL to select distinct class, CD and&lt;/P&gt;
&lt;P&gt;run&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;code on the result of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus assuming that CLASS is character type.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Dec 2016 15:25:06 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-12-21T15:25:06Z</dc:date>
    <item>
      <title>Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320517#M70614</link>
      <description>&lt;P&gt;Howdy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with a variable called "CLASS" (character variable) that contains 23 different values in it. Another variable called "CD" (character variable) has unique codes in it associated with each value in "CLASS". I want to create macro variables for each value found in "CLASS" containing the associated codes from "CD". In other words, I need to create 23 macro variables with their related codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Normally, I would do PROC SQL :INTO for this, but I do not know how to customize it so that it efficiently creates all the macro variables I need at once with their corresponding codes. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if things need to be made clearer!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 14:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320517#M70614</guid>
      <dc:creator>TXSASneophyte</dc:creator>
      <dc:date>2016-12-21T14:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320519#M70615</link>
      <description>&lt;P&gt;Well, firstly, don't. &amp;nbsp;Macro isn't the place to be manipulating data, that is what Base SAS is for. &amp;nbsp;Macro just generates text.&lt;/P&gt;
&lt;P&gt;If you show why you want to do this, I can simplfy for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your question, you can merge the two and do select into as normal:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; select &amp;nbsp;catx('-',A.VAR1,B.VAR2)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; into &amp;nbsp; &amp;nbsp; :MVAR&lt;/P&gt;
&lt;P&gt;&amp;nbsp; from &amp;nbsp; &amp;nbsp;TABLE1 A &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; full join TABLE2 B&lt;/P&gt;
&lt;P&gt;&amp;nbsp; on...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But really, there are far bettter ways of programming to avoid all the above.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320519#M70615</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-21T15:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320521#M70616</link>
      <description>&lt;P&gt;This task is much better suited to a DATA step than SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;call symputx(class, cd);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that the values for CLASS are legitimate SAS names.&amp;nbsp; It uses the values of CLASS as the names of the macro variables.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320521#M70616</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-21T15:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320524#M70618</link>
      <description>&lt;P&gt;This is great! Is there a way to do this procedure but only make macro variables for the unique values? The current code made duplicate macro variables because there are duplicate values in "CLASS", but there are only 23 unique values. I ask just to learn and make this a tidier! My initial thought is to create a separate dataset with only the unique values and then running your code. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320524#M70618</guid>
      <dc:creator>TXSASneophyte</dc:creator>
      <dc:date>2016-12-21T15:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320525#M70619</link>
      <description>&lt;P&gt;You can use SQL to select distinct class, CD and&lt;/P&gt;
&lt;P&gt;run&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;code on the result of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus assuming that CLASS is character type.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320525#M70619</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-21T15:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320527#M70620</link>
      <description>&lt;P&gt;Yes, creating a separate data set first would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be ways to create the macro variables in the same step that performs the subsetting.&amp;nbsp; Here are a couple of ideas that may or may not apply, depending on how your data is structured:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set have (obs=23);&lt;/P&gt;
&lt;P&gt;call symputx(class, cd);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by class;&lt;/P&gt;
&lt;P&gt;if first.class then call symputx(class, cd);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320527#M70620</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-21T15:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple macro variables from values of one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320534#M70623</link>
      <description>&lt;P&gt;Perfect, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 15:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-macro-variables-from-values-of-one-variable/m-p/320534#M70623</guid>
      <dc:creator>TXSASneophyte</dc:creator>
      <dc:date>2016-12-21T15:50:10Z</dc:date>
    </item>
  </channel>
</rss>

