Your SAS programs, embedded in web apps and elsewhere

Calling SAS Macro from HTML onClick() event.

Reply
N/A
Posts: 0

Calling SAS Macro from HTML onClick() event.

I'm trying to kick off a SAS macro from an HTML onClick event.

I've tried having the onClick event trigger a JavaScript function, and call macro to execute sql query.

I'm using the Stored Process Server. I have a Stored
Process holding not only the job to be run, but also the code for generating a web GUI.

The user pressed the button. Run the macro.

my code here.

[pre]
%macro displayRecord;
proc sql;
select empname from employTable where empcode=123;
PROC SQL NOPRINT;
SELECT DISTINCT LEFT(PUT(COUNT(NAME),32.)) INTO : empTot FROM employTable WHERE empcode=123;
QUIT;

%global maxName;
%put &empTot;
%let n=1;
%do %until (&n>&empTot);
%let maxName=&n;
%global Name&n;
%let n=%eval(&n+1);
%end;
%let n=1;

PROC SQL;
SELECT DISTINCT NAME INTO : Name&n - : Name&empTot FROM employTable WHERE empcode=123;
QUIT;
%mend;

%put &maxName;


%macro releteRecord;
proc sql;
DELETE FROM employTable where empcode=123;
quit;

%mend;

%macro emp;
data _null_;
file _webout;
put '<HTML>';
put '<script LANGUAGE="JavaScript">';
put 'function removeRec(selectbox){';
put " var index = document.getElementById('items').selectedIndex; ";
put ' var list1 =document.getElementById("items");';
put " alert(document.getElementById('items').value); ";
put ' var i;';
put ' for(i=list1.length-1; i>=0; i--){';
put ' if(list1[i].selected){';
put ' selectbox.remove(i);'; // this will remove from the list. not in table.
put ' }';
put ' }';
put '}';
put "</script>";
put '<FORM ID="FORM1" METHOD="LINK" ACTION="do" target="_self">';
put '<INPUT TYPE="hidden" NAME="_program" VALUE="/Test/TestForm">';

put '<table>';
put '<tr>';
put '<td><h4>Employee detail</h4></font></td>';
put '<td>';
put '<select multiple name="items" size="11"> ';
%let n=1;
%do %until (&n>&maxName);
%let Namev=%superq(Name&n);
put "<option value= %bquote("&Namev")>&Namev</option>";
%let n=%eval(&n+1);
%end;
put ' </select> ';
put '</td>';
put '<tr>';
put ' <td align="left"><input type="button" value="Remove" class="border" onClick="removeItem(items)";"/></td>';
put '</tr>';
put '</table>';
put '</FORM>';
put '</body>';
put '</html>';
run;
%mend;

%emp;
[/pre]

Corrected formatting issues


Message was edited by: Vince@SAS Corrected formatting issues


Message was edited by: Vince@SAS
Ask a Question
Discussion stats
  • 0 replies
  • 551 views
  • 0 likes
  • 1 in conversation