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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoSilva
Quartz | Level 8

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

3 REPLIES 3
BrunoSilva
Quartz | Level 8

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.

DavidPhillips2
Rhodochrosite | Level 12

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

BrunoSilva
Quartz | Level 8

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

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!

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