Search code examples
pythonsassaspy

Saspy Table Names in the Library


I want to use SASPy to put the names of tables within a library into a list as strings.

I tried this but sasdata() module does not work on my computer:

sas = saspy.SASsession()

tables = sas.sasdata(library=library_name).list_tables()

for table in tables:
    print(table)

Solution

  • list_tables() is a method of the SAS session object. The way you're using this is not a valid use of sasdata(). The corrected code is below.

    sas    = saspy.SASsession()
    tables = sas.list_tables('sashelp')
    
    for table, typ in tables:
        print(table)
    
    AACOMP
    AARFM
    ADSMSG
    AFMSG
    AIR
    AIRLINE
    ...