DATA Step, Macro, Functions and more

less options in Dropdown for HTML form

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

less options in Dropdown for HTML form


Hi ,

I am building an HTML form with dropdown boxes where the user can select values.. I am getting the value of the dropdown from a flatfile into a dataset and then into a macro variable which I use to display in the HTML page.

through the options are coming up, the drop down displays only max of 5 values. Kindly let me know how I can display the whole list of values . Kindly Advice

code :

data work.empnature;

infile " file location" dlm=',';

input  emp_nature :$200.;

run;

proc sql;

select distinct '<option value=" ' ||strip(emp_nature)||' ">' ||strip(emp_nature)||'</option>'

into : options separated by ','

from work.empnature;

quit;

data _NULL_;

file _webout;

input;

line=resolve(_infile_);

put line;

cards4;

<html>

<head></head>

<body>

<table>

<tr><td>Employment</td>

<td>

<select name ="emp_nature">

&options

</select>

</td></tr>

</table>

</body>

</html>

;;;;

run;


Accepted Solutions
Solution
‎03-29-2015 11:33 PM
Occasional Contributor
Posts: 12

Re: less options in Dropdown for HTML form

From the quick testing I did, the data step that reads the cards - the line var is created with a length of $200, so if you have many options, the html options syntax will quickly use up this space and you may end up with truncated html options code - the result is that only the first few options display.

Try adding a length statement e.g.:

data _NULL_;

file _webout;

length line $2000;

You may even need to make this longer if there are many options.

Mark

View solution in original post


All Replies
SAS Employee
Posts: 20

Re: less options in Dropdown for HTML form

As far as I know, there is no restriction on the number of options being displayed.

I suspect it may be a problem with the value of the macro variable.

When viewing the Stored Process try and right click on the browser and select View Source...

Then you will see what the browser received from your code.

Regards,

Michael

Occasional Contributor
Posts: 19

Re: less options in Dropdown for HTML form

Hi Michael,

I am getting the values from a dataset into a macro variable, but it doesn't throw the error of my macro exceeding the length. and when I print the macro with the put statement, as a part of the debug part, the macro variable displays all the values in the log . But when it is expected to display the same by substituting the macro variable in the HTML dropdown element, it displays only 2 values.

I can understand if the records from data set are not inserted into the macro variable due to space constrain, but here I have all the values in the macro variable just that it is not displaying properly .

<select name ="emp_nature">

&options

</select>

Super User
Super User
Posts: 6,502

Re: less options in Dropdown for HTML form

Don't use comma between the generated <OPTION> tags.

You need to watch out for characters in your file that HTML will treat as special.  You should use HTMLENCODE() function to protect them.

You also might want to switch to using PROC STREAM instead of the custom DATA step.  Then you could write the values to a separate file using a data step and avoid the risk of the hitting the maximum macro variable or data step variable length.

proc sql noprint;

select distinct

cats('<option value='

     ,quote(htmlencode(trim(emp_nature),'amp lt gt quot apos 7bit'))

     ,'>'

     ,htmlencode(trim(emp_nature),'amp lt gt quot apos 7bit')

     ,'</option>'

     )

into Smiley Surprisedptions separated by ' '

from work.empnature

;

quit;

Occasional Contributor
Posts: 19

Re: less options in Dropdown for HTML form

Thanks a ton TOM,

I have now a more refined working code Smiley Happy

Solution
‎03-29-2015 11:33 PM
Occasional Contributor
Posts: 12

Re: less options in Dropdown for HTML form

From the quick testing I did, the data step that reads the cards - the line var is created with a length of $200, so if you have many options, the html options syntax will quickly use up this space and you may end up with truncated html options code - the result is that only the first few options display.

Try adding a length statement e.g.:

data _NULL_;

file _webout;

length line $2000;

You may even need to make this longer if there are many options.

Mark

Occasional Contributor
Posts: 19

Re: less options in Dropdown for HTML form

Thanks a lot Mark.

your solution worked .. simple and precise Smiley Happy

🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 448 views
  • 6 likes
  • 4 in conversation