BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anand6666
Calcite | Level 5


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;

1 ACCEPTED SOLUTION

Accepted Solutions
MarkBodt_NZ
Obsidian | Level 7

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

6 REPLIES 6
MichaelLarsen
SAS Employee

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

Anand6666
Calcite | Level 5

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>

Tom
Super User Tom
Super User

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;

Anand6666
Calcite | Level 5

Thanks a ton TOM,

I have now a more refined working code Smiley Happy

MarkBodt_NZ
Obsidian | Level 7

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

Anand6666
Calcite | Level 5

Thanks a lot Mark.

your solution worked .. simple and precise Smiley Happy

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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