BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nmasel
Fluorite | Level 6

Hi,

 

I am reading in a SAS program and I lose all of the leading spaces when writing the file back out.  Is there a way to preserve this spacing?  I'm using SAS 9.4.

 

Here is my code to write out the file.

/**************************************************************************************************************
* Write out your program
**************************************************************************************************************/
filename final "C:\Users\nmasel\Downloads\tsfae01b_new.sas";

data _null_;
file final;
set addnew(keep=string);
put addnew;
run;

 

Here is an example of the contents of work.addnew:

 

   data adsl;

   set a_in.adsl(where=(&whr. and fasfl = "Y"));

 

      trtan = coalesce(trt04an, trt03an, trt02an, trt01an);

 

      if trtan = 1 then do;

         output;

         trtan = 2;

         output;

         trtan = 6;

         output;

      end;

      else do;

         output;

         trtan = 6;

         output;

      end;

 

      keep usubjid fasfl mribd trtan;

 

   run;

 

 

--Nick

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It looks like the name of the variable being written should be STRING (not ADDNEW).  But assuming that gets fixed ...

 

As you have seen, the PUT statement can remove leading blanks.  You can specify to keep them, by adding that instruction as part of the PUT statement.  Assuming that STRING has a length of 80 (and is the proper variable name), you could use:

 

put string $char80.;

 

That should preserve the leading blanks.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

It looks like the name of the variable being written should be STRING (not ADDNEW).  But assuming that gets fixed ...

 

As you have seen, the PUT statement can remove leading blanks.  You can specify to keep them, by adding that instruction as part of the PUT statement.  Assuming that STRING has a length of 80 (and is the proper variable name), you could use:

 

put string $char80.;

 

That should preserve the leading blanks.

nmasel
Fluorite | Level 6
Thank you!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 306 views
  • 0 likes
  • 2 in conversation