Using Macro Variables in SASPy

Reply
Contributor
Posts: 50

Using Macro Variables in SASPy

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.

 

c = sas.submit("""
%let sal=salary;
data low;
    set _csv;
    if &sal='low' then output;
run;

""")

Super User
Posts: 12,148

Re: Using Macro Variables in SASPy

Posted in reply to michelconn

michelconn wrote:

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.

 

c = sas.submit("""
%let sal=salary;
data low;
    set _csv;
    if &sal='low' then output;
run;

""")


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.

And things involving macros will generally have much more usable detail if:

options mprint symbolgen ;

is run prior to anything involving macros.

Ask a Question
Discussion stats
  • 1 reply
  • 81 views
  • 0 likes
  • 2 in conversation