As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


HTML Input

From sasCommunity
Jump to: navigation, search

Adding HTML input to your SAS/Intrnet page. This page will demonstrate how to code some HTML input elements. It is assumed that the SAS/intrnet programming and creating the HTML input elements are understood.

Main Program

The main program creates all the elements and puts a submit button to demonstrate each element. This is the HTML program that calls the main SAS program. The debug option has been set to 131 to web macro variables being passed into the programs and to see the log from the programs.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES"  CONTENT="0">
   <TITLE>SAS Demostration</TITLE>
 
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#8000080" ALINK="#FF0000">
 
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td valign="middle" align="left" bgcolor="#183F6E">
<font face="Arial,Helvetica" color="#FFFFFF"><b>SAS Intrnet Demostration of Radio Buttons, Text Boxes, Drop-Down List and Checkboxes.
</b></font>
</td>
<td> <a href="http://www2.sas.com/dispatcher/"><img src="saslogo.gif"
  border=0 alt="SAS Powered Logo"></a></td>
</tr>
</table>
<p>
This web page will demostrate how to code some of the HTML Form objects.<br>
See <A href="http://www.w3schools.com/html/html_forms.asp"> www.w3schools.com </a> for information on the objects.
<p><b> Press the execute button to begin </b>
<FORM ACTION="/cgi/broker.exe">
<INPUT TYPE="HIDDEN" NAME="_SERVICE" VALUE="default6">
<INPUT TYPE="HIDDEN" NAME="_PROGRAM" VALUE="sasWpDEV.SASDemoHTML.sas">
<INPUT TYPE="SUBMIT" VALUE="Execute" >
<INPUT TYPE="hidden" NAME="_DEBUG" VALUE="131">
</FORM>
</body>
</HTML>

This is the main SAS program that creates the input elements. Even though the body of page is complete with /HTML tag, a form can be be added to the page. Make sure the FORM is written to the new page before the input element. SAS is writing a new page that can be submitted.

%macro debug;
dm log 'clear';
options nocenter;
title 'SAS Demostration of HTML Form Objects';
%mend debug;
 
*need to make the turn off the protection special characters*;
ods path(prepend) work.templat(update);
proc template;                                                             
  define style styles.temp;
     parent=styles.minimal;
       style batch from batch /
           frame=void
           PROTECTSPECIALCHARS=OFF
		   ;
  end;                                                                     
run;                                                                       
 
options symbolgen;
%put NOTE: SysUserID=&sysuserid;
ods listing close;
ods escapechar='^';
ods HTML body=_webout (TITLE='SASDemoHTML') style=styles.temp;
 
*create the permanent the SAS dataset for this demostration*;
libname mylib 'd:\$temp';
data mylib.class;
set  sashelp.class;
run;
 
***********************************************************************************************;
* radio button
***********************************************************************************************;
* form action must go before any HTML controls*;
* Give the user "dont delete" button *;
data null;
file print;
put '<FORM ACTION="/cgi/broker.exe">';
put '<INPUT NAME="DeleteObs" TYPE=radio checked VALUE="0" > Dont delete any observations';
run;
 
* use Proc Report for greater customization its display and take advantage of pseudo columns*;
PROC REPORT HEADLINE NOWD MISSING NOCENTER data=mylib.class
STYLE(REPORT)=[BORDERWIDTH=0 BORDERCOLOR=GRAY]                           
STYLE(HEADER)=[FONT_SIZE=3 BACKGROUND=WHITE VJUST=T]                     
STYLE(COLUMN)=[FONT_SIZE=3]; 
column DeleteIt _all_;
define DeleteIt  / center style=[protectspecialchars=off];
compute DeleteIt /  char length=99;
  row+1;
  deleteIt='<INPUT NAME="DeleteObs" TYPE=radio VALUE="' || compress(put(row,best.)) ||  '" > ' || compress(put(row,best.));
  endcomp;
run;
 
*generate all the observation for a single deletion*;
data null;
file print;
put '^S={FONT_WEIGHT=BOLD}Delete the selected observation from above';
put '<INPUT TYPE="HIDDEN" NAME="_SERVICE" VALUE="default6">';
put '<INPUT TYPE="HIDDEN" NAME="_PROGRAM" VALUE="sasWpDEV.SASDemoHTML_radio.sas">';
put '<INPUT TYPE="SUBMIT" VALUE="Delete" >';
put '<INPUT TYPE="hidden" NAME="_DEBUG" VALUE="131">';
put '</FORM>';
run;
 
***********************************************************************************************;
* text boxes
***********************************************************************************************;
data null;
file print;
put '^S={FONT_WEIGHT=BOLD}Insert an observation';
put '<FORM ACTION="/cgi/broker.exe">';
put '<table><tr>';
put '<td>Name</td><td>Sex</td><td>Age</td><td>Height</td><td>Weight</td></tr><tr>';
put '<td><input type=text name="Name"   value="" size=10></td>';
put '<td><input type=text name="Sex"    value="" size=10></td>';
put '<td><input type=text name="Age"    value="" size=10></td>';
put '<td><input type=text name="Height" value="" size=10></td>';
put '<td><input type=text name="Weight" value="" size=10></td>';
put '</tr></table>';
put '<INPUT TYPE="HIDDEN" NAME="_SERVICE" VALUE="default6">';
put '<INPUT TYPE="HIDDEN" NAME="_PROGRAM" VALUE="sasWpDEV.SASDemoHTML_text.sas">';
put '<INPUT TYPE="SUBMIT" VALUE="Insert" >';
put '<INPUT TYPE="hidden" NAME="_DEBUG" VALUE="131">';
put '</FORM>';
run;
 
***********************************************************************************************;
* drop down  
***********************************************************************************************;
data null;
file print;
set mylib.class end=_lastrec_;
if _n_=1 then do; 
  put '<FORM ACTION="/cgi/broker.exe">';
  put '<select name="namelist">';
  end;
put '<option value="' name +(-1)'">' name '</option>';
if _lastrec_ then do;
   put '</select>';
   put '^S={FONT_WEIGHT=BOLD}Show the Record';
   put '<INPUT TYPE="HIDDEN" NAME="_SERVICE" VALUE="default6">';
   put '<INPUT TYPE="HIDDEN" NAME="_PROGRAM" VALUE="sasWpDEV.SASDemoHTML_dropdown.sas">';
   put '<INPUT TYPE="SUBMIT" VALUE="Show" >';
   put '<INPUT TYPE="hidden" NAME="_DEBUG" VALUE="131">';
   put '</FORM>';
   end;
run;
 
***********************************************************************************************;
* check box
***********************************************************************************************;
* use proc report 'before the header' text ability for the HTML form*;
PROC REPORT HEADLINE NOWD MISSING NOCENTER data=mylib.class
STYLE(REPORT)=[BORDERWIDTH=0 BORDERCOLOR=GRAY]
STYLE(HEADER)=[FONT_SIZE=3 BACKGROUND=WHITE VJUST=T protectspecialchars=off] /*protectspecialchars allows the HTML code*/
STYLE(COLUMN)=[FONT_SIZE=3] 
split='!'; *changes the split char so it does not interfers with the HTML slash*;
column ('<FORM ACTION="/cgi/broker.exe">' CheckIt _all_);
define  CheckIt  / center style=[protectspecialchars=off];
compute CheckIt / char length=99;
  row+1;
  CheckIt='<INPUT NAME="Checkit" TYPE=checkbox VALUE="' || compress(put(row,best.)) ||  '" > ' || compress(put(row,best.));
  endcomp;
run;
 
data null;
file print;
put '^S={FONT_WEIGHT=BOLD}Check the selected observation(s) from above';
put '<INPUT TYPE="HIDDEN" NAME="_SERVICE" VALUE="default6">';
put '<INPUT TYPE="HIDDEN" NAME="_PROGRAM" VALUE="sasWpDEV.SASDemoHTML_checkbox.sas">';
put '<INPUT TYPE="SUBMIT" VALUE="Check" >';
put '<INPUT TYPE="hidden" NAME="_DEBUG" VALUE="131">';
put '</FORM>';
run;
 
run;
ods HTML close;
run;

Radio Button to delete a record

The selected record number will be a in the macro variables passed via the radio button.

options symbolgen;
ods listing close;
ods escapechar='^';
ods HTML body=_webout (TITLE='SASDemoHTML') style=minimal;
 
data mylib.class;
file print;
set  mylib.class;
if _n_=&deleteObs then do;
   put "Observation # &deleteObs deleted";
   put "It had these values: " _all_;
   delete;
   end;
run;
title 'Dataset after the deletion';
PROC REPORT HEADLINE NOWD MISSING NOCENTER data=mylib.class
STYLE(REPORT)=[BORDERWIDTH=0 BORDERCOLOR=GRAY]                           
STYLE(HEADER)=[FONT_SIZE=2 BACKGROUND=WHITE VJUST=T]                     
STYLE(COLUMN)=[FONT_SIZE=2]; 
column obs _all_;
compute obs;
  dsobs + 1;
  obs = dsobs;
  endcomp;
run;
 
ods HTML close;
run;

Text Box to insert in a record

The text boxes will be passed in the macro variables. The program adds the data and shows the new dataset. Numbers are passed in as strings and converted into numbers.

options symbolgen;
ods listing close;
ods escapechar='^';
ods HTML body=_webout (TITLE='SASDemoHTML') style=minimal;
 
data mylib.class;
file print;
set mylib.class end=_lastrec_;
output;
if _lastrec_ then do;
   put 'The inserted record data is:';
   Name  ="&Name";
   Sex   ="&Sex";
   Age	 =input("&Age"   ,comma32.);
   Height=input("&Height",comma32.);
   Weight=input("&Weight",comma32.);
   output;
   put _all_;
   end;
run;
 
title 'Dataset after the insertion';
PROC REPORT HEADLINE NOWD MISSING NOCENTER data=mylib.class
STYLE(REPORT)=[BORDERWIDTH=0 BORDERCOLOR=GRAY]                           
STYLE(HEADER)=[FONT_SIZE=2 BACKGROUND=WHITE VJUST=T]                     
STYLE(COLUMN)=[FONT_SIZE=2]; 
column obs _all_;
compute obs;
  dsobs + 1;
  obs = dsobs;
  endcomp;
run;
 
ods HTML close;
run;

Drop Down List to show a record

Each name is loaded into the drop down list. The program finds the name and shows it.

options symbolgen;
%put NOTE: SysUserID=&sysuserid;
ods listing close;
ods escapechar='^';
ods HTML body=_webout (TITLE='SASDemoHTML') style=minimal;
 
data null;
file print;
set  mylib.class;
if name="&nameList" then put _all_;
run;
 
ods HTML close;
run;

Checkbox to select records to show on a graph

Passes the record numbers via the macro variables and makes a graph.

options symbolgen;
%put NOTE: SysUserID=&sysuserid;
ods listing close;
ods escapechar='^';
*http://support.sas.com/kb/17/990.html;
ods html body=_webout(title="SASDemoHTML")  path=&_tmpcat (url=&_replay) charset=' ' style=minimal headtext='<LINK REL="SHORTCUT ICON"HREF="/cgi/static/elements/favicon.ico">';
 
data null;
file print;
*nothing selected*;
if not symexist('Checkit0') and not symexist('Checkit') then do;
   call symput('Checkit0','0');
   put 'Nothing selected so no graph created';
   end;
*just one selected*;
if not symexist('Checkit0') and  symexist('Checkit') then do;
   call symput('Checkit0',"1");
   call symput('Checkit1',"&Checkit");
end;
run;   
 
data graphit;
file print;
set  mylib.class;
do i=1 to &checkit0;
   if _n_=symget('Checkit'||compress(put(i,best.))) then do;
     put _all_;
     output;
     end;
end;
run;
 
goptions reset=all;
goptions gsfname=_webout gsfmode=replace dev=GIF ftext=swiss;
*http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#gplvrbl1-ex.htm*;
proc gplot;
 plot height*weight;
 symbol1 interpol=rcclm95
       value=dot
       cv=darkred
       ci=black
       co=blue
       ;
run;
quit;
 
run;
ods HTML close;
run;