Your SAS programs, embedded in web apps and elsewhere

Saving a JavaScript Value to a SAS Global Variable

Accepted Solution Solved
Reply
Super Contributor
Posts: 497
Accepted Solution

Saving a JavaScript Value to a SAS Global Variable

I’ve been researching how to integrate SAS and JavaScript.

Is there a way to set a SAS variable equal to JavaScript variable in SAS 9.2?  I have a stored process inside of Information Delivery Portal using a Web URL that displays a stored process inside a webpage like setup.  I found that SAS can use HTML variables when the user clicks refresh so long as the variables are Global Variables.  Changing the HTML variable changes the SAS variable. I want to access one of the Global variables via JavaScript so that I can reference the value when the page reloads. I only need the JavaScript to extract the value of:

$(""#degStudLev"").multipleSelect('getSelects');

Is there a way extract this value as html or assign it to a Global SAS variable?

The code concept is:

%Global degStudLev degStudLevComma;


/*degStudLev is assigned a value*/

%macro javaScriptFunctions;

            data _null_ ;

             file _webout ;

             put '<script type="text/JavaScript">' ;

            put "function saveMultiSelection() {";

                        put "alert('Selected values: ' + $(""#degStudLev"").multipleSelect('getSelects'));";

/*this is the line doesn't save the variable back to SAS Global Variable degStudLevComma.*/

                        put "var degStudLevComma = $(""#degStudLev"").multipleSelect('getSelects');";

            put "}";

%mend;

%javaScriptFunctions;


Accepted Solutions
Solution
‎05-26-2015 11:53 AM
Contributor
Posts: 50

Re: Saving a JavaScript Value to a SAS Global Variable

Posted in reply to DavidPhillips2

If the multiple selection is a List Box when you submit the form it is converted to multiple macro variables in SAS.

If not a List Box, how about you save to a hidden text input, when your form is submited you get the value on SAS as a macro variable.

View solution in original post


All Replies
Solution
‎05-26-2015 11:53 AM
Contributor
Posts: 50

Re: Saving a JavaScript Value to a SAS Global Variable

Posted in reply to DavidPhillips2

If the multiple selection is a List Box when you submit the form it is converted to multiple macro variables in SAS.

If not a List Box, how about you save to a hidden text input, when your form is submited you get the value on SAS as a macro variable.

Super Contributor
Posts: 497

Re: Saving a JavaScript Value to a SAS Global Variable

Posted in reply to BrunoSilva

The hidden textbox should work.  Currently doing a proof of concept.

Contributor
Posts: 50

Re: Saving a JavaScript Value to a SAS Global Variable

Posted in reply to DavidPhillips2

How about using HttpRequestObject (Ajax) to interact with SAS and using Sessions to keep the Variable Value between interactions?

See links bellow with the puzzle parts:

https://support.sas.com/resources/papers/proceedings10/014-2010.pdf

SAS Stored Processes: Sessions

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 621 views
  • 0 likes
  • 2 in conversation