Reputation: 4674
I have a problem like this at work:
Some system requires a specific input like:
0000051420189999999 ABC12345678<20 SPACES>;
Which is a (some digit)
+ Sample_Date
+ (some digit)
+ x amount of spaces
+ Sample_KEY
+ y amount of spaces
.
I read a few online post about string concatenation and converting date into string. But the trailing spaces are always eliminated at the end.
PROC SQL;
CREATE TABLE WORK.MAINFRAME_FILE AS
SELECT CAT('0000',
COMPRESS(PUT((Sample_Date), MMDDYY10.), '/',),
'9999999 ',
Sample_KEY,
' ')
AS INPUT FORMAT=$100.
FROM WORK.TEST
;
QUIT;
How can I add some trailing spaces at the end, say 20? Thanks
Upvotes: 1
Views: 1808
Reputation: 63434
If you're putting this into a SAS dataset, the spaces are there automatically as long as the field length is defined sufficiently. All SAS columns are by definition space-padded to full length. You might not see them depending on how you're looking at the field, but they're there internally.
If you're putting this into a SQL Server table or similar, it will probably depend on the particular RDBMS you're connecting to how to accomplish this.
SAS example - note x
has the ascii representation '20'x which is space:
PROC SQL;
CREATE TABLE WORK.MAINFRAME_FILE AS
SELECT CAT('0000',
COMPRESS(PUT((today()), MMDDYY10.), '/',),
'9999999 ',
Name,
' ')
AS INPUT FORMAT=$100.
FROM SASHELP.CLASS
;
QUIT;
data your_file;
set work.mainframe_file;
x = substr(input,60,1);
put x= $HEX2.;
run;
Upvotes: 3