Help using Base SAS procedures

Adding trailing blanks to alphanumeric characters

Reply
Frequent Contributor
Posts: 125

Adding trailing blanks to alphanumeric characters

Adding trailing blanks to alphanumeric characters SAS code

Super User
Super User
Posts: 7,942

Re: Adding trailing blanks to alphanumeric characters

Posted in reply to chennupriya

Hi,

data want;

  length b $200;

  a="ABCD1234";

  b=repeat("0",20-length(strip(a)))||strip(a);

run;

For trailing, just move the strip(a) before the repeat.

Trusted Advisor
Posts: 1,228

Re: Adding trailing blanks to alphanumeric characters

Posted in reply to chennupriya

data want;

  length b $20;

  a="ABCD1234";

  b=a;

run;

Super User
Super User
Posts: 7,942

Re: Adding trailing blanks to alphanumeric characters

Oh, trailing blanks, I should read the question more thoroughly.

Frequent Contributor
Posts: 125

Re: Adding trailing blanks to alphanumeric characters

hi ,

i want to export to Csv file after coding

sso we use something like dat_null_

AAnd put function now length is $12.

and it shd be A25

Super User
Posts: 5,498

Re: Adding trailing blanks to alphanumeric characters

Posted in reply to chennupriya

If you are using DATA _NULL_ and a PUT statement to write out the data, it is easy to write out trailing blanks.  Add a format specification to the PUT statement, for example:

put varname $25. ','  ... more variables ...;

This will write a total of 25 characters for VARNAME, including trailing blanks as needed to reach that length of 25.

Good luck.

Super User
Super User
Posts: 7,039

Re: Adding trailing blanks to alphanumeric characters

Posted in reply to chennupriya

Why?  You mention writing a CSV, but by definition a CSV file would normally NOT have trailing blanks.

Ask a Question
Discussion stats
  • 6 replies
  • 221 views
  • 0 likes
  • 5 in conversation