Help using Base SAS procedures

Add Trailing Spaces to Variable

Reply
Contributor
Posts: 25

Add Trailing Spaces to Variable

I have data as below.
var
1
1P

3
3F
2
;
i want to exprt this to text file using file statement.
DATA _NULL_;
SET TEST(OBS = 10000);
FILE 'C:\RDIP_1.TXT';
PUT var;
RUN;

output should be with the same data and if there is only one character the second character should be space.
1 (+ 1 spaces)
1P (no spaces)
(2 spaces)
3 (+ 1 spaces)
(2 spaces)
3F (no spaces)
2 (+ 1 spaces)
Regular Contributor
Posts: 241

Re: Add Trailing Spaces to Variable

Use a format when you put. Here is a simple example. Hope this helps.



   /* test dataset */


   data one;


     length var $2;


     do var = "1""1P""""3""3F""2";


       output;


     end;


   run;


 


   /* print out to a text file */


   filename text temp;


   data _null_;


     set one;


     file text;


     put var $2.;


   run;


 


   /* check */


   data _null_;


     infile text;


     input;


     put "***" _infile_ "***";


   run;


   /* on lst


   ***1 ***


   ***1P***


   ***  ***


   ***3 ***


   ***3F***


   ***2 ***


   */


   filename text clear;

N/A
Posts: 0

Re: Add Trailing Spaces to Variable

hello,

another possible solution is based on file options lrecl and pad added to your statement:

DATA _NULL_;
SET TEST(OBS = 10000);
FILE 'C:\RDIP_1.TXT' lrecl=2 pad;
PUT var;
RUN;

Marius
Ask a Question
Discussion stats
  • 2 replies
  • 1375 views
  • 0 likes
  • 3 in conversation