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

Hi guys,

 

 Can someone help please?

 

 How can I add an extra blank at the end of a character variable and then export it to a .TXT file with the blank at the end.

 

 I have tried to concatenate name = name || " "; but doesn't work. Please see the code below (just copy and paste):

 

 

 The problem is to add an extra blank, the proc export is working fine, but without the extra blank at the end.

 

Thanks and regards!!

 

data have1;
input name & $2.;
datalines;
a
;
run;

data have1;
set have1;
name = name || " ";
run;

PROC EXPORT DATA = have1 OUTFILE = '/sas/teste.TXT' REPLACE ;
PUTNAMES=NO;
RUN;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It's not too difficult to program it yourself:

 

data _null_;

set have;

file '/sas/teste.txt' noprint;

put name $3.;

run;

 

There's still a question of delimiters between fields, which fields you really need to write out, whether to add a blank after numerics, etc.  But you can program it yourself.

 

You can't add a blank to the end of the variable NAME, because its length doesn't change.  Given that NAME is defined as having a length of 2, this statement will not change the value of NAME:

 

name = name || 'abcde';

 

There's only room for 2 characters, so "abcde" doesn't fit and gets truncated.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

It's not too difficult to program it yourself:

 

data _null_;

set have;

file '/sas/teste.txt' noprint;

put name $3.;

run;

 

There's still a question of delimiters between fields, which fields you really need to write out, whether to add a blank after numerics, etc.  But you can program it yourself.

 

You can't add a blank to the end of the variable NAME, because its length doesn't change.  Given that NAME is defined as having a length of 2, this statement will not change the value of NAME:

 

name = name || 'abcde';

 

There's only room for 2 characters, so "abcde" doesn't fit and gets truncated.

FreelanceReinh
Jade | Level 19

Hi @anonymous_user,

 

--- I see, @Astounding was faster ---

 

Please note that your second data step is redundant in two ways:

  1. Variable NAME has length 2 (thanks to your informat specification $2.), hence it contains already the desired trailing blank after 'a'.
  2. Whatever you tried to append using 
    name = name || "whatever"
    it would not appear in variable NAME, because the expression right of the equals sign would append it after the last character of NAME (i.e. after the trailing blank), but there is no room for a third, fourth, ... character in variable NAME (left of the equals sign) because of its length 2.

The problem with PROC EXPORT is that this procedure uses (what is called) list output, as can be seen in the log of the PROC step:

put name $ ;

This will always shed trailing blanks.

 

What you need is formatted output:

put name $2.;

So, you could use the DATA _NULL_ step from the log of PROC EXPORT as a basis and modify it to use formatted output, as shown above.

Ksharp
Super User

You can make both blank and | as delimiter :

 

data _null_;
set sashelp.class;
file '/folders/myfolders/xx.txt' dlmstr=' |';
put (_all_) (:);
run;
LinusH
Tourmaline | Level 20

Odd request. What kind of receiving system needs a trailing blank to do it's import?

I think interchanged data should be as clean as possible, and adding extra blanks generally doesn't add any value to the data.

Data never sleeps

The recieving system will use the .txt file to update a table on the mainframe, so when the program reads blank it wont change that specific info, when it is <> from blank he updates the record. Don't know exactly why it works like that, but that the way it is.

Thanks and regards!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 8119 views
  • 4 likes
  • 5 in conversation