<?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: passing values from macro var into sas data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974983#M377997</link>
    <description>&lt;P&gt;Dead simple. A DO loop from 1 to countw("&amp;amp;list.","+"), extract single values with scan("&amp;amp;list.",i,"+"), and OUTPUT.&lt;/P&gt;</description>
    <pubDate>Sat, 13 Sep 2025 06:42:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-09-13T06:42:36Z</dc:date>
    <item>
      <title>passing values from macro var into sas data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974980#M377995</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say I have a macro variable with values separated by '+'&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets say that I want to pass the values in macro var into sas data set.&lt;/P&gt;
&lt;P&gt;Please note that number of arguments in the macro var can be different so I am looking for dynamic solution that can do it for each number of arguments in macro var.&lt;/P&gt;
&lt;P&gt;Here is an example for the wanted data set based on the macro var list&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let List=Health+Wealth+age+Education_in_Years+Ind_SPort_Lover;

Data Want;
input VAR_Name $20.;
cards;
Health
Wealth
age
Education_in_Years
Ind_Sport_Lover
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Sep 2025 05:53:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974980#M377995</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-09-13T05:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: passing values from macro var into sas data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974983#M377997</link>
      <description>&lt;P&gt;Dead simple. A DO loop from 1 to countw("&amp;amp;list.","+"), extract single values with scan("&amp;amp;list.",i,"+"), and OUTPUT.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Sep 2025 06:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974983#M377997</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-09-13T06:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: passing values from macro var into sas data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974985#M377998</link>
      <description>&lt;P&gt;As long as the length of the macro variable is less than 32K bytes you can use normal data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do i=1 to countw(symget('list'),'+');
    length var_name $32 ;
    var_name = scan(symget('list'),i,'+');
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the string is (or could be) longer then you might want to use a macro %DO loop instead.&amp;nbsp; Which will require defining a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro list2ds(dsname,list);
%local i ;
data &amp;amp;dsname;
  length var_name $32 ;
%do i=1 %to %sysfunc(countw(&amp;amp;list,+));
  var_name = "%scan(&amp;amp;list,&amp;amp;i,+)"; output;
%end;
run;
%mend list2ds;
%list2ds(dsname=want,list=&amp;amp;list)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Sep 2025 12:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-values-from-macro-var-into-sas-data-set/m-p/974985#M377998</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-13T12:55:59Z</dc:date>
    </item>
  </channel>
</rss>

