BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Vemula
Obsidian | Level 7

Hi all,

 

I am using SAS Enterprise Guide to execute Python code. We have SAS 9.4M6. I have used below ways but are unsuccessful. Could you please help me with it?

 

Python Code:

 

import tempfile
import errno

def isWritable(path😞
    try:
        testfile = tempfile.TemporaryFile(dir = path)
        testfile.close()
    except OSError as e:
        if e.errno == errno.EACCES:  # 13
            return False
        e.filename = path
        raise
    return True
print(isWritable("/path/project"))

 

1:

proc fcmp;
declare object py(python);
rc = py.infile("/path/get_d_list.py");
put rc=;
rc = py.publish();
rc = py.call("isWritable", "/path/vyashoda");
/* Result = py.results["MyOutputKey"];*/
/* put Result=;*/
run;

 

2:

x "python3 /path/get_d_list.py";

 

3:
data _null_;
call system ('python3 /path/get_d_list.py');
run;

 

4:

%macro pwdls;
%sysexec %str(pwd;python3 /path/get_d_list.py);
%mend pwdls;
%pwdls;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

I never used python in SAS, but you should use 

 

filename CMD pipe 'python3 /path/get_d_list.py 2>&1';
data _null_;

  infile CMD;

  input;

  put _infile_;
run;

 

instead of

 

data _null_;
call system ('python3 /path/get_d_list.py');
run;

 

to see OS messages.

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

I never used python in SAS, but you should use 

 

filename CMD pipe 'python3 /path/get_d_list.py 2>&1';
data _null_;

  infile CMD;

  input;

  put _infile_;
run;

 

instead of

 

data _null_;
call system ('python3 /path/get_d_list.py');
run;

 

to see OS messages.

Vemula
Obsidian | Level 7

Thanks much Chris for your help. Appreciate it. It's working for me.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 678 views
  • 1 like
  • 2 in conversation