<?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: Using Macro Variables in SASPy in Developers</title>
    <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503142#M271</link>
    <description>&lt;P&gt;Hey, just saw this, and I have to say, I really didn't provide a useful example of this in that Advanced topics section &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;So, I just added a sample notebook to the saspy-examples site showing how you can use this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sassoftware/saspy-examples/blob/master/SAS_contrib/Using_SYMGET_and_SYMPUT.ipynb" target="_blank"&gt;https://github.com/sassoftware/saspy-examples/blob/master/SAS_contrib/Using_SYMGET_and_SYMPUT.ipynb&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this post, I can run in line mode and show the same thing here too;The notebook is prettier though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tom64-3&amp;gt; python3.5&lt;BR /&gt;Python 3.5.5 (default, Feb 6 2018, 10:56:47)&lt;BR /&gt;[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux&lt;BR /&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; import saspy&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas = saspy.SASsession(cfgname='sdssas')&lt;BR /&gt;SAS Connection established. Subprocess id is 28930&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas&lt;BR /&gt;Access Method = STDIO&lt;BR /&gt;SAS Config name = sdssas&lt;BR /&gt;WORK Path = /sastmp/SAS_workC57A00007120_tom64-3/&lt;BR /&gt;SAS Version = 9.04.01M4D11092016&lt;BR /&gt;SASPy Version = 2.2.9&lt;BR /&gt;Teach me SAS = False&lt;BR /&gt;Batch = False&lt;BR /&gt;Results = Pandas&lt;BR /&gt;SAS Session Encoding = WLATIN1&lt;BR /&gt;Python Encoding value = cp1252&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('new_var', 52)&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symget('new_var')&lt;BR /&gt;52&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('nuther_var', 'Hi there')&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symget('nuther_var')&lt;BR /&gt;'Hi there'&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; py_var = sas.symget('nuther_var')&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print(py_var)&lt;BR /&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('from_py_var', py_var+" y'all")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print(sas.symget('from_py_var'))&lt;BR /&gt;Hi there y'all&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
    <pubDate>Wed, 10 Oct 2018 15:56:14 GMT</pubDate>
    <dc:creator>sastpw</dc:creator>
    <dc:date>2018-10-10T15:56:14Z</dc:date>
    <item>
      <title>Using Macro Variables in SASPy</title>
      <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/430128#M269</link>
      <description>&lt;P&gt;Can some one please give me an example of symget and symput from saspy? I read over the section in advanced topics but I don't understand how to create a SAS macro variable that is recognized by python. I've created a working macro variable using the submit command but it was only recognized within the submit command. Is it possible to create a SAS macro variable within the submit command and pass the value to a python variable? I can image using a CSV or the SAS log to do it but that seems clunky.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c = sas.submit("""&lt;BR /&gt;%let sal=salary;&lt;BR /&gt;data low;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set _csv;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if &amp;amp;sal='low' then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;""")&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 19:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/430128#M269</guid>
      <dc:creator>michelconn</dc:creator>
      <dc:date>2018-01-23T19:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in SASPy</title>
      <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/430207#M270</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38419"&gt;@michelconn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Can some one please give me an example of symget and symput from saspy? I read over the section in advanced topics but I don't understand how to create a SAS macro variable that is recognized by python. I've created a working macro variable using the submit command but it was only recognized within the submit command. Is it possible to create a SAS macro variable within the submit command and pass the value to a python variable? I can image using a CSV or the SAS log to do it but that seems clunky.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;c = sas.submit("""&lt;BR /&gt;%let sal=salary;&lt;BR /&gt;data low;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set _csv;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if &amp;amp;sal='low' then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;""")&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Much better, and likely easier, than "images" of the log is to copy and paste text directly from the log into a code window opened using the forum {I} icon.&lt;/P&gt;
&lt;P&gt;And things involving macros will generally have much more usable detail if:&lt;/P&gt;
&lt;P&gt;options mprint symbolgen ;&lt;/P&gt;
&lt;P&gt;is run prior to anything involving macros.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 23:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/430207#M270</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-23T23:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in SASPy</title>
      <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503142#M271</link>
      <description>&lt;P&gt;Hey, just saw this, and I have to say, I really didn't provide a useful example of this in that Advanced topics section &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;So, I just added a sample notebook to the saspy-examples site showing how you can use this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sassoftware/saspy-examples/blob/master/SAS_contrib/Using_SYMGET_and_SYMPUT.ipynb" target="_blank"&gt;https://github.com/sassoftware/saspy-examples/blob/master/SAS_contrib/Using_SYMGET_and_SYMPUT.ipynb&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this post, I can run in line mode and show the same thing here too;The notebook is prettier though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tom64-3&amp;gt; python3.5&lt;BR /&gt;Python 3.5.5 (default, Feb 6 2018, 10:56:47)&lt;BR /&gt;[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux&lt;BR /&gt;Type "help", "copyright", "credits" or "license" for more information.&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; import saspy&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas = saspy.SASsession(cfgname='sdssas')&lt;BR /&gt;SAS Connection established. Subprocess id is 28930&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas&lt;BR /&gt;Access Method = STDIO&lt;BR /&gt;SAS Config name = sdssas&lt;BR /&gt;WORK Path = /sastmp/SAS_workC57A00007120_tom64-3/&lt;BR /&gt;SAS Version = 9.04.01M4D11092016&lt;BR /&gt;SASPy Version = 2.2.9&lt;BR /&gt;Teach me SAS = False&lt;BR /&gt;Batch = False&lt;BR /&gt;Results = Pandas&lt;BR /&gt;SAS Session Encoding = WLATIN1&lt;BR /&gt;Python Encoding value = cp1252&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('new_var', 52)&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symget('new_var')&lt;BR /&gt;52&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('nuther_var', 'Hi there')&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; sas.symget('nuther_var')&lt;BR /&gt;'Hi there'&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; py_var = sas.symget('nuther_var')&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print(py_var)&lt;BR /&gt;Hi there&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; sas.symput('from_py_var', py_var+" y'all")&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; print(sas.symget('from_py_var'))&lt;BR /&gt;Hi there y'all&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 15:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503142#M271</guid>
      <dc:creator>sastpw</dc:creator>
      <dc:date>2018-10-10T15:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in SASPy</title>
      <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503153#M272</link>
      <description>&lt;P&gt;And, not to make you think that you can only use these methods by together themselves, No, you can intermix them with your SAS code, and so all the things you would expect. You can get at macro variables already in SAS with symget() and you can use macro variables created with symput() in your SAS code too. Here a few more lines showing that (hope the output from head() formats correctly on this):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;gt; ll = sas.submit(''' &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;... %let what_happened=it worked!; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;... &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;... data a; x=symget('from_py_var'); y=symget('new_var');run; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;... ''') &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; data_a = sas.sasdata('a', results='text') &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; data_a.head() &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt; The SAS System &lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT face="andale mono,times"&gt; Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y &lt;/FONT&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;FONT face="andale mono,times"&gt; 1&amp;nbsp; &amp;nbsp; &amp;nbsp;Hi there y'all&amp;nbsp; &amp;nbsp; &amp;nbsp; 52&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; print(sas.symget('what_happened')) &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;it worked! &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;Tom&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 16:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503153#M272</guid>
      <dc:creator>sastpw</dc:creator>
      <dc:date>2018-10-10T16:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using Macro Variables in SASPy</title>
      <link>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503188#M273</link>
      <description>Thanks for the follow up, that explanation makes a lot of sense.</description>
      <pubDate>Wed, 10 Oct 2018 18:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/Using-Macro-Variables-in-SASPy/m-p/503188#M273</guid>
      <dc:creator>michelconn</dc:creator>
      <dc:date>2018-10-10T18:41:24Z</dc:date>
    </item>
  </channel>
</rss>

