BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LarrryHoyle
Calcite | Level 5

I'm trying to write a custom task that allows users to enter attributes into a form that builds a Proc Datasets to modify a copy of a dataset.

I can get the proc datasets to run correctly with a button event handler that looks like:

SAS.Tasks.Toolkit.SasSubmitter submitter = new SAS.Tasks.Toolkit.SasSubmitter(ActiveServer);

                // holds SAS log output

                string log;

                // submit program and wait for completion

                submitter.SubmitSasProgramAndWait(FinalSasCode, out log);

where FinalSasCode has the program I want to run.

I have a property in the Model also called FinalSasCode and I can set it with the program text (and see in the log that it is set, but when GetSASCode() is invoked the property returns an empty string (as can be seen in the log).

Is this come kind of timing or thread issue? When does GetSasCode() get invoked?

public override string GetSasCode()
    {
        try
        {
           
            dlg.logger.InfoFormat(" /*  From GetSasCode FinalSasCode:  */ \n proc contents data = {0}.{1}; run;\n {2} \n /*   */", Consumer.ActiveData.Library, Consumer.ActiveData.Member, FinalSasCode);
           

            return string.Format(" /*   task complete */ \n proc contents data = {0}.{1}; run;\n {2} \n /*   */", Consumer.ActiveData.Library, Consumer.ActiveData.Member, FinalSasCode);          
        }
        catch (Exception ex)
        {
            dlg.logger.InfoFormat(" Exception caught in GetSASCode {0}", ex.Message);
            return string.Format(" /*  Exception generated in GetSasCode   */");
        }
    }

From the logger:

2013-10-07 19:18:56,229 [Main] INFO  DataLogger [(null)] -  /*  From GetSasCode FinalSasCode:  */

proc contents data = EXTEST.SALES; run;

 

/*   */

This is what is submitted with the OK button:

/*   task complete */

proc contents data = EXTEST.SALES; run;

 

/*   */

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Larry,

Do you need the code to run while the task is visible?  Or simply after the OK button is clicked?

If you need the code to run in EG after you click OK, you do not need the SasSubmitter piece.  The SasSubmitter class allows you to run SAS statements while your task is visible and then collect/use the results within your UI.  An example is the "solve macro expression" piece in the Macro Variable Viewer example.

It's important to understand the different "modes" of a custom task:

Registration (or discovery) - the few methods that are used to add your task to the menu, determine the name, category, icon.

Design time - when your task shows its UI and allows the end user to make selections.  All selections must be saved in the XmlState member (facilitated by GetXmlState and RestoreStateFromXml within the SasTask-derived task -- methods that you must override).

Run time - EG creates a new instance of your task class and provides the XmlState (which you can process in RestoreStateFromXml), then calls GetSasCode -- in which you construct a SAS program based on the settings you saved.

These topics are covered in more detail in my custom tasks book.  See Chapter 4: Meet the Custom Task APIs.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

View solution in original post

2 REPLIES 2
ChrisHemedinger
Community Manager

Larry,

Do you need the code to run while the task is visible?  Or simply after the OK button is clicked?

If you need the code to run in EG after you click OK, you do not need the SasSubmitter piece.  The SasSubmitter class allows you to run SAS statements while your task is visible and then collect/use the results within your UI.  An example is the "solve macro expression" piece in the Macro Variable Viewer example.

It's important to understand the different "modes" of a custom task:

Registration (or discovery) - the few methods that are used to add your task to the menu, determine the name, category, icon.

Design time - when your task shows its UI and allows the end user to make selections.  All selections must be saved in the XmlState member (facilitated by GetXmlState and RestoreStateFromXml within the SasTask-derived task -- methods that you must override).

Run time - EG creates a new instance of your task class and provides the XmlState (which you can process in RestoreStateFromXml), then calls GetSasCode -- in which you construct a SAS program based on the settings you saved.

These topics are covered in more detail in my custom tasks book.  See Chapter 4: Meet the Custom Task APIs.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
LarrryHoyle
Calcite | Level 5

Thanks very much. I missed the Design time vs Run Time distinction in Chapter 4, and had not overridden XMLState. I thought that it was just for restoring the user interface when the task was modified in future EG sessions.

I see how that works now.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 930 views
  • 0 likes
  • 2 in conversation