How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

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>

*/


Accepted Solutions
Solution
‎01-20-2015 12:34 PM
Respected Advisor
Posts: 4,969

Re: How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

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.

View solution in original post


All Replies
Solution
‎01-20-2015 12:34 PM
Respected Advisor
Posts: 4,969

Re: How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

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.

Occasional Contributor
Posts: 14

Re: How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

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!

Senior User
Posts: 1

Re: How to remove trailing blanks when PUT statement resolves for HTML form retrieval?

works like a charm - thanks for posting this.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 507 views
  • 0 likes
  • 3 in conversation