Adding trailing blanks to alphanumeric characters SAS code
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.
data want;
length b $20;
a="ABCD1234";
b=a;
run;
Oh, trailing blanks, I should read the question more thoroughly.
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
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.
Why? You mention writing a CSV, but by definition a CSV file would normally NOT have trailing blanks.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.