<?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: How to Pass a macro var list to a SAS data variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217961#M40154</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let mvarlist=A B C D;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp1;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;Var3=scan("&amp;amp;mvarlist", _N_, ' ');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Apr 2015 02:41:26 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2015-04-09T02:41:26Z</dc:date>
    <item>
      <title>How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217960#M40153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; %let mvarlist=A B C D;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAS data set temp has two variables Var1 and Var2 with four observations. The goal is to assgin A, B, C, D in mvarlist to a new sas variable Var3 in temp1 data so that Var3 has A, B, C, and D for its 4 observations repectively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp1;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;Var3=%scan(&amp;amp;mvarlist, _N_, ' ');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(1) I know the above argument _N_ in %scan() is not right since it need a number, not a sas variable. How to achieve the desired result?&lt;/P&gt;&lt;P&gt;(2) proc sql has a way to output a sas variable column to a macro var list, is there a way to do the opposite: write a macro list to a sas variable?&lt;/P&gt;&lt;P&gt;(3) What if mvarlist=1 2 3 4, I want to input it as a numeric SAS variable?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 02:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217960#M40153</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2015-04-09T02:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217961#M40154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let mvarlist=A B C D;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp1;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;Var3=scan("&amp;amp;mvarlist", _N_, ' ');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 02:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217961#M40154</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-04-09T02:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217962#M40155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are so close, but you need to remember that code generated by macro processing is compiled BEFORE the data step starts running.&lt;/P&gt;&lt;P&gt;So instead of the macro %SCAN() function which would run just once you need to use the data step SCAN() function that will execute for each iteration of the data step.&amp;nbsp; (Note also that your %SCAN() function cannot work since you have passed a character string, _N_,&amp;nbsp; as the second argument where an integer is needed.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;VAR3 = scan( "&amp;amp;mvarlist",_n_) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Or to make a numeric variable if the values of MVARLIST were digits instead of letters you can add an INPUT() function.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%let value_list=1 2 3 4 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;VAR3 = input(scan("&amp;amp;value_list",_n_),32.) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 02:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217962#M40155</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-04-09T02:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217963#M40156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%LET mvarlist= A B C D;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var1;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp1;&lt;/P&gt;&lt;P&gt;do until(scan("&amp;amp;mvarlist", _n_, ' ') ne ' ');&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;Var3=scan("&amp;amp;mvarlist", _n_, ' ');&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 05:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217963#M40156</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-04-09T05:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217964#M40157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1 and 2 has been solved by Jagadishkatam.&lt;/P&gt;&lt;P&gt;3) Just use Var3=input(scan("&amp;amp;mvarlist", _n_, ' '),3.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 07:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217964#M40157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-04-09T07:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217965#M40158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why use macro variables for this in the first place?&amp;nbsp; Base SAS/SQL both have perfectly good merging procedures. Put you macro variables in a dataset and use normal merging techniques.&amp;nbsp; Far simpler, easier to read/use code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Apr 2015 08:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217965#M40158</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-09T08:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217966#M40159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using SAS data merging is an alterntive way. The reason is that I am going to write a macro so that input parameter is easier to create as a macro list than creating a sas data as a input parameter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 19:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217966#M40159</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2015-04-10T19:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217967#M40160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Why use do until loop, is it really necesary?&lt;/P&gt;&lt;P&gt;2. The set statement can be put outside of do loop?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 20:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217967#M40160</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2015-04-10T20:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Pass a macro var list to a SAS data variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217968#M40161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, you don't need a do loop. Did you try stat's or Tom's suggested code? The following worked for me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET mvarlist= A B C D;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var1 var2;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 4&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;3 2&lt;/P&gt;&lt;P&gt;4 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Var3=scan("&amp;amp;mvarlist", _n_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for proc sql, sql has no way to know record order, so no method could be guaranteed to work unless you have a variable that indicates record order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, the following will work, but may not always produce the same results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *, scan("&amp;amp;mvarlist.",monotonic()) as var3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Apr 2015 21:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Pass-a-macro-var-list-to-a-SAS-data-variable/m-p/217968#M40161</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-10T21:24:05Z</dc:date>
    </item>
  </channel>
</rss>

