Mark,
I'm glad Chris' solution will work for you. I agree, that sounds like the best route to take. However, I wanted to provide a little more information for clarity...
The "EGPrjObj.CodeCollection.Add" call in your example adds a new program to the EG project (equivalent to interactive File->New->Program). The key here is that this new program is embedded (stored in the EG project (.egp file)) by default, rather than a shortcut to a .sas file on disk. This is important because the _SASPROGRAMFILE macro value is empty (two single quotes) for embedded programs, since there is no physical program file to reference. For example, you'll see this near the top of the log:
%LET _SASPROGRAMFILE='';
So, EG is generating the code that sets the _SASPROGRAMFILE macro in this case (both interactively and via automation), it just happens to be set to empty, since it is an embedded program (there is no program file).
If you add an existing .sas file to an EG project (ex. File->Open->Program, interactively), the _SASPROGRAMFILE macro will contain the path to the .sas file (when run interactively or via automation). The root problem is there does not appear to be a way to add an existing .sas program (reference/shortcut) to an EG project via automation. I did not find an API in the current automation interface for doing this.
Hope that helps.
Casey
... View more