<?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: Converting list of macro variables into dataset variables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470201#M14700</link>
    <description>&lt;P&gt;From where does this arbitrary heap of macro variables originate? You might alleviate your problems by storing the values in a dataset from the start.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jun 2018 06:09:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-06-14T06:09:08Z</dc:date>
    <item>
      <title>Converting list of macro variables into dataset variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470148#M14691</link>
      <description>&lt;P&gt;I have a list of macro variables as shown below:&lt;/P&gt;&lt;P&gt;%let a=40;&lt;/P&gt;&lt;P&gt;%let b=55;&lt;/P&gt;&lt;P&gt;%let c=25;&lt;/P&gt;&lt;P&gt;%let d=38;&lt;/P&gt;&lt;P&gt;%let e = 41 and so on.&lt;/P&gt;&lt;P&gt;I would like to convert this to a sas dataset in the manner of&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp; &amp;nbsp;d&amp;nbsp; &amp;nbsp; &amp;nbsp;e&lt;/P&gt;&lt;P&gt;40&amp;nbsp; &amp;nbsp;55&amp;nbsp; &amp;nbsp; 25&amp;nbsp; &amp;nbsp;38&amp;nbsp; &amp;nbsp;41&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could not find anything on a quick way to do this. All I can think of is writing a data step with datalines to create the dataset. Is there a quicker way to do it, given I have large number of variables? Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 23:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470148#M14691</guid>
      <dc:creator>Mahip</dc:creator>
      <dc:date>2018-06-13T23:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting list of macro variables into dataset variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470158#M14692</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a=40;

%let b=55;

%let c=25;

%let d=38;

%let e = 41;

data w;
a=&amp;amp;a;
b=&amp;amp;b;
c=&amp;amp;c;
d=&amp;amp;d;
e=&amp;amp;e;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jun 2018 00:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470158#M14692</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-14T00:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting list of macro variables into dataset variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470172#M14697</link>
      <description>&lt;P&gt;Are all your values numeric?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you use all existing macro variables without omitting any?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to do something like this, but I can't test this now so I can't work out the final details until tomorrow:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select name || '=' || value&amp;nbsp; into : varlist separated by ';' from dictionary.macros&lt;/P&gt;
&lt;P&gt;where scope ne 'AUTOMATIC';&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;amp;varlist;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few details to work out ... SCOPE is probably the wrong variable name for the WHERE clause ... in fact all the names from dictionary.macros need to be checked&amp;nbsp; To patch the code, you will need to look at the structure of dictionary.macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;***************** EDITED:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;The original program wasn't too far off.&amp;nbsp; Here's a modified version that should work a little better:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; select catx('=', name, value) into : varlist separated by ';' from dictionary.macros&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&amp;nbsp; where (scope ne 'AUTOMATIC') and (substr(name, 1, 3) not in ('SQL', 'SYS') );&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;It generates assignment statements for all your macro variables, however ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;It works properly for numeric variables only, since it generates statements like&amp;nbsp; a=5;&amp;nbsp; It won't add quotes around the "5" unless you get fancier with the code.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 14:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470172#M14697</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-14T14:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Converting list of macro variables into dataset variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470201#M14700</link>
      <description>&lt;P&gt;From where does this arbitrary heap of macro variables originate? You might alleviate your problems by storing the values in a dataset from the start.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 06:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Converting-list-of-macro-variables-into-dataset-variables/m-p/470201#M14700</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-14T06:09:08Z</dc:date>
    </item>
  </channel>
</rss>

