Hello, we are retrieving character data from a database into an HTML form in a Stored Process in the Stored Process Web Application. That approach is going well in general, but we have found that trailing blanks are being added to the original data values so that, when the HTML form is generated, the blanks become part of the value shown in the form and the blanks would be incorrectly included in the value when the form is resubmitted. Is there a way to resolve the PUT statements without adding trailing blanks to the values? We can probably fix this with JavaScript in the browser once the form loads, but would prefer to avoid the issue in the first place. Any help would be greatly appreciated, thank you!
data test;
length ID1 $1 ID2 $1 ID3 $1 ID4 $1 ID5 $1 date1 $10 date2 $10 date3 $10 date4 $10 date5 $10;
input ID1 $ ID2 $ ID3 $ ID4 $ ID5 $ DATE1 $ DATE2 $ DATE3 $ DATE4 $ DATE5 $;
datalines;
1 2 3 4 5
01/10/2015 01/11/2015 01/12/2015 01/13/2015 01/14/2015
;
/*The blanks are not part of the original values and, even if they were, we should be able to remove them...*/
data test;
set test;
ID1 = strip(ID1);
DATE1=strip(DATE1);
run;
data _null_;
set test;
put '<input id="ID1" name="ID1" value="' ID1'"></input>';
put '<input id="DATE1" name="DATE1" value="' DATE1'"></input>';
run;
/*Log shows:
<input id="ID1" name="ID1" value="1 "></input>
<input id="DATE1" name="DATE1" value="01/20/2015 "></input>
*/
/*Want to resolve without the extra trailing space in the HTML value attribute, as in:
<input id="ID1" name="ID1" value="1"></input>
<input id="DATE1" name="DATE1" value="01/20/2015"></input>
*/
The PUT statement leaves a trailing blank after writing unformatted variables. You can see this easily enough by testing:
ID1 = 'rkgrc';
put '*' ID1 '*';
Removing the blanks from the PUT statement won't help:
put '*'ID1'*';
You need to add instructions to tell SAS to back up a space before continuing to write:
put '*' ID1 +(-1) '*';
In your code, you would have to add +(-1) to both PUT statements, immediately following the variable name toward the end of the statement.
Good luck.
The PUT statement leaves a trailing blank after writing unformatted variables. You can see this easily enough by testing:
ID1 = 'rkgrc';
put '*' ID1 '*';
Removing the blanks from the PUT statement won't help:
put '*'ID1'*';
You need to add instructions to tell SAS to back up a space before continuing to write:
put '*' ID1 +(-1) '*';
In your code, you would have to add +(-1) to both PUT statements, immediately following the variable name toward the end of the statement.
Good luck.
Thank you! I have seen the "+(-1)" before in SAS User Group papers, etc., but I never knew exactly what purpose it served, so this is great. Thanks again!
works like a charm - thanks for posting this.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.