BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CurtisMackWSIPP
Lapis Lazuli | Level 10

I have a FCMP step that ads a conditional format to a spreadsheet.  It works great in traditional SAS, but in Enterprise Guide it returns the errors:

ERROR: Unable to publish program for foreign language execution.
ERROR: Error reported in function 'python:PUBLISH' in statement number 4 at line 10531 column 5.

Here is the code:

  proc fcmp;
    declare object py(python);
    submit into py;
    def MyFunc(arg1,arg2):
      "Output: MyKey"
      from openpyxl import load_workbook
      from openpyxl.styles import Color, PatternFill, Font, Border
      from openpyxl.styles.differential import DifferentialStyle
      from openpyxl.formatting import Rule
      from openpyxl.formatting.rule import FormulaRule, ColorScaleRule, CellIsRule
      wb=load_workbook(filename=arg1)
      ws=wb.active
      red_fill = PatternFill(bgColor="FFC7CE")
      dxf = DifferentialStyle(fill=red_fill)
      r = Rule(type="expression", dxf=dxf, stopIfTrue=True)
      r.formula = ['$D4<>$E4']
      ws.conditional_formatting.add("A4:E100", r)
      wb.save(filename=arg2)
    endsubmit;
    rc=py.publish();
    rc=py.call("MyFunc","c:\temp\temp.xlsx","C:\TEMP\ActionDatesQC_2020.xlsx");
  run; 

I have attached the spreadsheet it is modifying.

 

My system environment paths are working for traditional SAS, is there a different place they need to be set for EG?

MAS_M2PATH = C:\Program Files\SASHome\SASFoundation\9.4\tkmas\sasmisc\mas2py.py
MAS_PYPATH  = C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe

I know that is an unusual path for Python, but I hope to start calling ArcGis functions in the future.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Just to confirm - you have SAS 9.4M6 and  a required hotfix (or SAS 9.4M7)? See doc, which you might have already been following.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

When using EG to connect to SAS, you need to make sure the environment variables are set in the session/config where SAS is launched.  In a client-server environment, this might be in a sas.sh startup script, or perhaps you can set in the sasv9_usermods.cfg that is included for your session. (That's typically an admin task.)


Use the SYSGET function to check the values of the environment variables to make sure they are what you expect.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
CurtisMackWSIPP
Lapis Lazuli | Level 10

That was definitely a good idea to pursue.  However I am running EG against a local installation.  I ran the following code:

data _null_;
  optstr=sysget('MAS_M2PATH');
  put 'MAS_M2PATH:' optstr;
  optstr=sysget('MAS_PYPATH');
  put 'MAS_PYPATH:' optstr;
run;

and got the correct results:

MAS_M2PATH:C:\Program Files\SASHome\SASFoundation\9.4\mas2py.py
MAS_PYPATH:C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe
ChrisHemedinger
Community Manager

Just to confirm - you have SAS 9.4M6 and  a required hotfix (or SAS 9.4M7)? See doc, which you might have already been following.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
CurtisMackWSIPP
Lapis Lazuli | Level 10

I hadn't applied the hot fix both because it was working in foundation, and because the SAS hot fix process is inexcusable 🙂

I went ahead and installed all the hot fixes, which at first I thought was a mistake. After that my code quit working in foundation as well.  However, I ran it again to pick up the handful of fixes that failed the first time.  That fixed it!  

 

Thanks for you help!

 

DarrylLawrence
Obsidian | Level 7

Hi 

 

We followed the instructions to add the MAS_M2PATH and MAS_PYPATH environment variables but the code still fails.

 

See log below and hotfixes installed for Base SAS.  

 

Are we missing a hotfix or is there something else that needs to be done.

 

We are running SAS Enterprise guide connecting to Linux.

 

NOTE: Writing HTML5(EGHTML) Body file: EGHTML

27        

28         proc fcmp outlib=work.fcmp.pyfuncs;

29         function MyPyFunc(FCMParg);

30         declare object py(python);

31         submit into py;

32         def TimesFive(PythonArg):

33             "Output: MyKey"

34             newvar = PythonArg * 5

35             return newvar

36         endsubmit;

37         rc = py.publish();

38         rc = py.call("TimesFive",FCMParg);

39         MyFCMPResult = py.results["MyKey"];

40         return(MyFCMPResult);

41         endsub;

42         run;

 

NOTE: Function MyPyFunc saved to work.fcmp.pyfuncs.

NOTE: PROCEDURE FCMP used (Total process time):

      real time           0.03 seconds

     cpu time            0.03 seconds

     

 

43        

44         options cmplib=work.fcmp;

45         data _null_;

46            x = MyPyFunc(5);

47            put x=;

48         run;

 

2                                                          The SAS System                           10:30 Thursday, January 26, 2023

 

ERROR: Unable to publish program for foreign language execution.

ERROR: Error reported in function 'python:PUBLISH' in statement number 5 at line 12 column 2.

       The statement was:

    0     (12:2)     rc = python:PUBLISH(  )

x=.

NOTE: DATA statement used (Total process time):

      real time           0.02 seconds

      cpu time            0.03 seconds

     

 

Host: lax
Product: base
Version: 9.4
Display Name: Base SAS
Hot Fix Entry: Hotfix D9T001
Hot Fix Entry: Hotfix D9T004
Hot Fix Entry: Hotfix D9T006
Hot Fix Entry: Hotfix D9T014
Hot Fix Entry: Hotfix D9T015
Hot Fix Entry: Hotfix D9T018
Hot Fix Entry: Hotfix D9T021
Hot Fix Entry: Hotfix D9T023
Hot Fix Entry: Hotfix D9T024
Hot Fix Entry: Hotfix D9T029
Hot Fix Entry: Hotfix D9T031
Hot Fix Entry: Hotfix D9T033
Hot Fix Entry: Hotfix D9T034
Hot Fix Entry: Hotfix D9T036
Hot Fix Entry: Hotfix D9T038
Hot Fix Entry: Hotfix D9T041
Hot Fix Entry: Hotfix D9T042
Hot Fix Entry: Hotfix D9T043
Hot Fix Entry: Hotfix D9T044
Hot Fix Entry: Hotfix D9T046
Hot Fix Entry: Hotfix D9T048
Hot Fix Entry: Hotfix D9T051
Hot Fix Entry: Hotfix D9T039
Hot Fix Entry: Hotfix D9T052
Hot Fix Entry: Hotfix D9T053
Hot Fix Entry: Hotfix D9T057
Hot Fix Entry: Hotfix D9T058
Hot Fix Entry: Hotfix D9T059
Hot Fix Entry: Hotfix D9T061
Hot Fix Entry: Hotfix D9T062
Hot Fix Entry: Hotfix D9T063
Hot Fix Entry: Hotfix D9T067
Hot Fix Entry: Hotfix D9T068
Hot Fix Entry: Hotfix D9T071
Hot Fix Entry: Hotfix D9T073
Hot Fix Entry: Hotfix D9T075
Hot Fix Entry: Hotfix D9T076
Hot Fix Entry: Hotfix D9T078
Hot Fix Entry: Hotfix D9T079
Hot Fix Entry: Hotfix D9T080
Hot Fix Entry: Hotfix D9T083
Hot Fix Entry: Hotfix D9T082
Hot Fix Entry: Hotfix D9T084
Hot Fix Entry: Hotfix D9T085
Hot Fix Entry: Hotfix D9T087
Hot Fix Entry: Hotfix D9T089
Hot Fix Entry: Hotfix D9T090
Hot Fix Entry: Hotfix D9T093
Hot Fix Entry: Hotfix D9T095
Hot Fix Entry: Hotfix D9T098
Hot Fix Entry: Hotfix D9T099
Hot Fix Entry: Hotfix D9T100
Hot Fix Entry: Hotfix D9T101
Hot Fix Entry: Hotfix D9T104
Hot Fix Entry: Hotfix D9T110
Hot Fix Entry: Hotfix D9T117
Hot Fix Entry: Hotfix D9T123
Hot Fix Entry: Hotfix D9T127
Hot Fix Entry: Hotfix D9T129
Hot Fix Entry: Hotfix D9T130
Hot Fix Entry: Hotfix D9T131
Hot Fix Entry: Hotfix D9T132
Hot Fix Entry: Hotfix D9T134
Hot Fix Entry: Hotfix D9T135
Hot Fix Entry: Hotfix D9T137
Hot Fix Entry: Hotfix D9T139
Hot Fix Entry: Hotfix D9T140
Hot Fix Entry: Hotfix D9T141
Hot Fix Entry: Hotfix D9T142
Hot Fix Entry: Hotfix D9T143
Hot Fix Entry: Hotfix D9T144
Display Version: 9.4_M6

 

 

ChrisHemedinger
Community Manager

@DarrylLawrence Is it possible that the SAS session has NOXCMD set, or a LOCKDOWN option? This is common in client/server configurations to limit the ability for end users of client apps to access the OS shell functions of a server. You would work with your SAS administrator to change this.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 2435 views
  • 0 likes
  • 3 in conversation