Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trailing Blanks

Status
Not open for further replies.

aybooth

MIS
Feb 6, 2004
9
US
How can I create a variable that will always 56 bytes long regardless of how many characters are in the original text string? I need to add trailing blanks so that the variable is always 56 bytes long. I can format and ensure the length is 56 but when I perform the length function on the variable it reduces to the true number of characters in the string.

Thanks

Anthony
 
Why do you need it to be 56 characters long all the time?

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
The length function does not count trailing blanks. So your string may still be 56 long. But, I also ask why do you need to have the string always 56 long?

Klaz
 
Hi
I am uploading a file against our mainframe and its expected length is 314 bytes. This is made up of other variables but after the acct number, phone number, status code it leaves me needing 56 for the comment field and 31 for an additional filler. the comment is 56 as that is the longest length of a single comment line on our system

Thanks
 
Ah,
Well, in that case you should write out the file as a fixed length record...
Code:
data _null_;
  file 'c:\test.txt'  recfm=f lrecl=314;

  put @1 field1
      @26 Field2
      ...
      ...
   ;
run;
This will give you a file with a fixed length as defined by the lrecl number.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Thanks that helps!
Another one. I am creating my file like this...

data _null_;
set outmain3(drop=var_chk);
file 'S:\CH\Risk\Cust_Assist\DDAHierarchy\outmain_test.data'recfm=f lrecl=314;
put @1 var;
run;

However the 314 record length is working but each records follows the previous, can I get it to drop each record onto its own line? so if this was opend in excel each row would contain only 1 record?

Thanks again

Anthony
 
Ah!
Yes, the way to do this would be to add a carriage return and a line feed at the end of the record.
Generally a fixed length file doesn't need that, however to do it so you can view it easily you would do this:-
Code:
data _null_;
set outmain3(drop=var_chk);
  file 'S:\CH\Risk\Cust_Assist\DDAHierarchy\outmain_test.data'recfm=f lrecl=316;
  put    @1 var
         @315  '0D'x
         @316  '0A'x
         ;
       
run;

Note, - I've put the record length out to 316 now to accomodate the CR and LF characters, so if the fixed length record HAS to be 314, you'll need to pull those back a bit to get it right.
'0D'x is the Hex code for a Carriage Return, the x after the quotes tells SAS that what is in the quotes is a Hex character. 0A is the line feed character.
I hope that this helps.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Chris,

Thank you very much for this!! You've been a great help.

Ant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top