BookmarkSubscribeRSS Feed
june_bug
Fluorite | Level 6

How do I maintain the spaces when exporting to text?

MichaelPearce
Obsidian | Level 7

Ah so you have 3 columns, need 173 length overall and need to maintain embedded spaces within the 3 columns.

So a small change to the example in reply 6 gives you:

data test;
  format col1-col3 $char20.;

  col1 = "no spaces";
  col2 = "no spaces";
  col3 = "no spaces";
  output;

  col1 = "  2 spaces";
  col2 = "   3 spaces";
  col3 = "    4 spaces";
  output;
run;

filename zout 'c:\testText.txt';

data _null_;
  set test;

  file zout;

  pos1 =   5 + (verify(col1,' ') - 1);
  pos2 =  50 + (verify(col2,' ') - 1);
  pos3 = 100 + (verify(col3,' ') - 1);

  put @pos1 col1 @pos2 col2 @pos3 col3 @173 ' ';
run;

filename zout;

data_null__
Jade | Level 19

I don't think you need to do all that measuring to get @ column.  $CHAR format will preserve leading blanks.

put (col1-col3) ($char49.) @173 ' ';
june_bug
Fluorite | Level 6

Hi Tom

There seems to be a space or 2 after the last character. How can I remove it or ensure that the 173 length ends at the last character.

june_bug
Fluorite | Level 6

Hi

Not to worry, I sorted it!

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!

How to Concatenate Values

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.

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
  • 19 replies
  • 25417 views
  • 2 likes
  • 5 in conversation