BookmarkSubscribeRSS Feed
chennupriya
Quartz | Level 8

Adding trailing blanks to alphanumeric characters SAS code

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

stat_sas
Ammonite | Level 13

data want;

  length b $20;

  a="ABCD1234";

  b=a;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

chennupriya
Quartz | Level 8

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

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 865 views
  • 0 likes
  • 5 in conversation