Читать книгу SAS Viya - Kevin D. Smith - Страница 10
Running CAS Actions
ОглавлениеJust like the help action, all of the action sets and actions are available as attributes and methods on the CAS connection object. For example, the userinfo action is called as follows.
In [8]: conn.userinfo()
Out[8]:
[userInfo]
{'anonymous': False,
'groups': ['users'],
'hostAccount': True,
'providedName': 'username',
'providerName': 'Active Directory',
'uniqueId': 'username',
'userId': 'username'}
+ Elapsed: 0.000291s, mem: 0.0826mb
The result this time is a CASResults object, the contents of which is a dictionary under a single key (userInfo) that contains information about your user account. Although all actions return a CASResults object, there are no strict rules about what keys and values are in that object. The returned values are determined by the action and vary depending on the type of information returned. Analytic actions typically return one or more DataFrames. If you aren’t using IPython to format your results automatically, you can cast the result to a dictionary and then print it using pprint for a nicer representation.
In [9]: from pprint import pprint
In [10]: pprint(dict(conn.userinfo()))
{'userInfo': {'anonymous': False,
'groups': ['users'],
'hostAccount': True,
'providedName': 'username',
'providerName': 'Active Directory',
'uniqueId': 'username',
'userId': 'username'}}
When calling the help and userinfo actions, we actually used a shortcut. In some cases, you might need to specify the fully qualified name of the action, which includes the action set name. This can happen if two action sets have an action of the same name, or an action name collides with an existing method or attribute name on the CAS object. The userinfo action is contained in the builtins action set. To call it using the fully qualified name, you use builtins.userinfo rather than userinfo on the CAS object. The builtins level in this call corresponds to a CASActionSet object that contains all of the actions in the builtins action set.
In [11]: conn.builtins.userinfo()
The preceding code provides you with the same result as the previous example does.