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;
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
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
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>
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 :options separated by ' '
from work.empnature
;
quit;
Thanks a ton TOM,
I have now a more refined working code
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
Thanks a lot Mark.
your solution worked .. simple and precise
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.