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;
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.
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.
Hi @anonymous_user,
--- I see, @Astounding was faster ---
Please note that your second data step is redundant in two ways:
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.
You can make both blank and | as delimiter :
data _null_;
set sashelp.class;
file '/folders/myfolders/xx.txt' dlmstr=' |';
put (_all_) (:);
run;
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.
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!
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.
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.