Your SAS programs, embedded in web apps and elsewhere

Saving the Value of an HTML Textbox to a SAS Global Variable

Accepted Solution Solved
Reply
Super Contributor
Posts: 497
Accepted Solution

Saving the Value of an HTML Textbox to a SAS Global Variable

Is there a way to save the value of a HTML textbox to a SAS Global Variable?


Hopefully my question isn’t too complicated. 

I found a way to use JavaScript and JQuery to include a list of checkeddropdown boxes in SAS using a Web URL Portlet.  I also found a way to send the contents of proc report or proc tabulate to Excel using a send to Excel button.  Both work perfectly separately but I’m having issues with them both combined.

The checked dropdown boxes uses

data _null_ ;

file _webout ;

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

put "function saveMultiSelection() {";

put "document.getElementById('degStudLevComma').value  = $(""#degStudLev"").multipleSelect('getSelects');";

put "document.getElementById('studyLevelComma').value  = $(""#studyLevel"").multipleSelect('getSelects');";

put "document.getElementById('sumLevComma').value  = $(""#sumlev"").multipleSelect('getSelects');";

put "}";

To save the value of the selected dropdown boxes to a HTML textbox after the user clicks refresh.

The Send to Excel uses

PUT "<a href=&SERVER/"@;

PUT "SASPortal/Director?_directive="@;

PUT "STPRun&_action=execute%nrstr(&_program)=%SYSFUNC(URLENCODE(&_PROGRAM))"@;

PUT "%nrstr(&FORMAT=EXCEL)%nrstr(&sumlev=)&sumlev"@;

PUT "%nrstr(&reportTy1=)&reportTy1"@;

PUT "%nrstr(&reportTy2=)&reportTy2"@;

PUT "%nrstr(&term=)&term"@;                                            

PUT "%nrstr(&studyLevel=)&studyLevel"@;

PUT "%nrstr(&measureTy=)&measureTy"@;          

PUT "%nrstr(&degStudLev=)&degStudLev"@;

PUT " onclick='saveMultiSelection();'><img src='https://sites.google.com/site/dashboardsamples/_/rsrc/1340285950455/home/export-icon.gif' alt='Export to Excel' title='Export to Excel' height='15' width='15' style='border:none;' /></a>";

To pass selected criteria to a self call of the same stored process. The self call does not pass the value of the hidden textboxes so I can’t use the same JavaScript method when using both.

Is there a way to save the value of the textbox to a SAS Global Variable so I can pass it to the same stored process maybe something like?

put "function saveSelectionExcel() {";

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

     put "studyLevel = $(""#studyLevel"").multipleSelect('getSelects');";

     put "sumLev= (""#sumlev"").multipleSelect('getSelects');";

put "}";

There is likely an easier way using SAS rather than JavaScript, i'm not sure how to do it in JavaScript either.


Accepted Solutions
Solution
‎07-01-2015 02:45 PM
Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

also set the value of the html field to the value of the variable.

View solution in original post


All Replies
Trusted Advisor
Posts: 3,215

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

Your question is describing how sas/intranet works with sessions. That product has been deprecated in favor of SP processes using metadata and the prompt manager.

You could review the session creation of sas/intranet and how that manages saved variables. But why?

---->-- ja karman --<-----
Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Researching SAS Sessions this might be what I need.

Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

This would work if I could assign the a session variable to the value returned via JavaScript.

e.g.

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


Something like this would work too but I need documentation to find the syntax to access the returned value of a JavaScript function in SAS:

%let saveStudLevComma = javascriptFunction(degStudLev);

Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

This worked.

put "document.getElementById('save_sumLevComma').value  = $(""#sumlev"").multipleSelect('getSelects');";

Solution
‎07-01-2015 02:45 PM
Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

also set the value of the html field to the value of the variable.

Occasional Contributor
Posts: 16

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to DavidPhillips2

I recieved the following bit of code from SAS support.  We are trying to do similiar things with added flexibility. I'm having trouble assigning varialbe names to dynamically created text boxes so I can append/ update back the values to a SAS table. also checkout Joe Flynn's paper here -> https://support.sas.com/resources/papers/proceedings09/330-2009.pdf

*  Begin EG generated code (do not edit this line); * *  Stored process registered by *  Enterprise Guide Stored Process Manager V6.1 * *  ==================================================================== *  Stored process name: test_webout *  ==================================================================== *; *ProcessBody; %STPBEGIN; *  End EG generated code (do not edit this line); /* --- Start of code for "Test Stored Process". --- */ /* add_update_delete_report.sas This program permits you to add,  */ /* update and delete observations from a SAS data set and to      */ /* produce a report.                                              */ /*END*/ /******************************************************************/ /*                                                                */ /* Name:    add_update_delete_report_stp.sas                    */ /*                                                                */ /* Purpose : Data Entry and Update Sample program.                */ /*          This program illustrates an approach to add, update, */ /*          and delete observations in a SAS data set.          */ /*                                                                */ /* NOTE: you must modify the LIBNAME MYLIB statement below.      */ /*                                                                */ /*  Create a stored process using this code.                    */ /*  Then, submit a request via your Web browser to execute it.  */ /*                                                                */ /******************************************************************/   /* You must modify the following LIBNAME statement to reference */   /* your own site-specific SAS library.                          */ libname mylib "/apps/sas/datasets/data15/MAHIMS/Data"; %global reqtype empno name address phoneno  ; %macro menu1;   data _null_;     file _webout;     thissrv = symget('_url');     thispgm = symget('_program');     put "

";     put "

Sample Employee Database Application

";     put 'Add New Employee

';     put 'Update Employee Information

';     put 'Delete an Employee

';     put 'Report of all Employees

';     put "

"; run; %mend menu1; %macro return_link;   data _null_;     file _webout;     thissrv = symget('_url');     thispgm = symget('_program');     put "

";     put "

";     put 'Return to Main Menu

';     put '';     put '

'; run; %mend return_link; %macro add_form;   /* Output data entry form */ data _null_;   file _webout;   thissrv = symget('_url');   thispgm = symget('_program');   put '

';   put '';   put '

Add New Employee Information

';   put '

';   put '';   put '';   put 'Employee Number:
';   put '
';   put 'Name:
';   put '
';   put 'Phone Number:
  ';   put '
';   put 'Address:
  ';   put '

';   put '';   put '

'; run; %return_link; %mend add_form; %macro addrec;   /* Update existing data set  */   proc sql;     create table work.results as     select * from mylib.employee           where empno = &empno;   run;   data _null_;  /* Check if empno already exists */     if (count=0) then do;       call symput('exists','no');       end;     else do;       call symput('exists','yes');     end;     stop;     set results nobs=count;   run;   %macro add_if_new;     %if ("&exists" eq "no") %then %do;       proc sql;       insert into mylib.employee         set empno=&empno, name = "&name", phoneno="&phoneno", address="&address";       quit;       data _null_;         file _webout;         put "Employee &name was added.

";       run;   %end;   %else %do;       data _null_;         file _webout;         put "

Sorry, Employee &empno already exists.

";       run;   %end;   %mend add_if_new;   %add_if_new;   %return_link; %mend addrec; %macro delete_it;   /* Delete an employee  */ proc sql;   create table work.results as   select * from mylib.employee           where empno = &empno;   run; data _null_;   set results;   call symput('name',name); run; proc sql;   delete from mylib.employee           where empno=&empno; quit; data _null_; file _webout; if "&name" ne "" then do;     put "Employee Number &empno - &name was deleted.

";   end; else do;     put "Sorry, Employee Number &empno was not found.

";   end; run; %return_link; %mend delete_it; %macro report;   ods listing close;   ods html body=_webout rs=none;   proc sort data=mylib.employee;     by empno;   run;   title "Employee Database";   footnote1 " ";   proc print data=mylib.employee;   run;   ods html close;   %return_link; %mend report; %macro update_form; data _null_; file _webout; thissrv = symget('_url'); thispgm = symget('_program'); put ''; put ''; put '

Update Employee Information

'; put '

'; put ''; put ''; put 'Enter Employee Number:
'; put '

'; put ''; put '

'; run; %return_link; %mend update_form; %macro delete_form; data _null_;   file _webout;   thissrv = symget('_url');   thispgm = symget('_program');   put '';   put '';   put '

Delete Employee

'; put '

';   put '';   put '';   put 'Enter Employee Number:
';   put '

';   put '';   put '

'; run; %return_link; %mend delete_form; %macro update;   proc sql;   create table work.results as   select * from mylib.employee           where empno = &empno;   run;   data _null_;   if (count = 0) then do;       file _webout;       put "";       put "Sorry, employee &empno does not exist

";       put "";   end;   set results nobs=count;   file _webout;   thissrv = symget('_url');   thispgm = symget('_program');   put '';   put '';   put '

Update Employee Information

';   put '

';   put '';   put '';   put 'Employee Number:
';   put '
';   put 'Employee Name:
';   put '
';   put 'Phone Number:
';   put '

';   put 'Address:
';   put '

';   put '';   put '

';   put '';   put '';   stop;   run;   %return_link; %mend update; %macro update_it; proc sql;   update mylib.employee     set name = "&name", phoneno="&phoneno", address="&address"     where empno=&empno; quit; data _null_; file _webout; put "Employee &empno was updated.

"; run; %return_link; %mend update_it; %macro ifexist(dsname);   /*  If the data set does not exist, then create it.    */   /*  This step is needed only when this demo is set up  */   /*  initially.                                          */   %local dsname;   %if %sysfunc(exist(&dsname)) %then;   %else %do;     %put it does not exist;     data &dsname;         format name $char25.;         format empno 8.;         format address $char40.;         format phoneno $char15.;         stop;     run;   %end; %mend ifexist; %macro main; %if "&reqtype" eq "add" %then %do;     %addrec; %end; %else %if "&reqtype" eq "addform" %then %do;           %add_form;       %end; %else %if "&reqtype" eq "report" %then %do;           %report;       %end; %else %if "&reqtype" eq "updform" %then %do;           %update_form;       %end; %else %if "&reqtype" eq "update" %then %do;           %update;       %end; %else %if "&reqtype" eq "update2" %then %do;           %update_it;       %end; %else %if "&reqtype" eq "delete" %then %do;           %delete_form;       %end;   %else %if "&reqtype" eq "delete2" %then %do;           %delete_it;       %end; %else %do;     %menu1; %end; %mend main; %ifexist(mylib.employee);    /* This step is needed only for setup */ %main; /* --- End of code for "Test Stored Process". --- */ *  Begin EG generated code (do not edit this line); ;*';*";*/;quit; %STPEND; *  End EG generated code (do not edit this line);

Super Contributor
Posts: 497

Re: Saving the Value of an HTML Textbox to a SAS Global Variable

Posted in reply to TimMandell

put"<input name='save_degStudLevComma' id='save_degStudLevComma' value =""&save_degStudLevComma"">

Make the variables Global.  Or Session variables.  So long as the Id is the same as the global variable the two are linked.


This also handles keeping the variables on page reload.


You have to do your update after the page reloads. Using the global or session variable. That part is pure SAS, no HTML.

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 942 views
  • 1 like
  • 3 in conversation