DATA Step, Macro, Functions and more

proc export lines with spaces at the end

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

proc export lines with spaces at the end

[ Edited ]

Hi all!

 

How can i export a data if have spaces at the and. I need this blank spaces at the end. I have a table with one cloumn (length $141.)

If i export the table to a txt cut the blank spaces at the end of the line and take a tabulator. How can i avoid this?

my code:

 

data _null_;
set table ;
call execute('proc export
data=x_table
outfile="C:\temp\sample.xt"
dbms=tab replace ;
putnames=no;
run;');
run;

 

now i have in the txt :

1 2 3 4                           xyz       XYZ(after that TABULATOR)

and i need this: 

1 2 3 4                           xyz       XYZ(after the i need spaces until that i reach the $141. length)

 

Thank for all help!!

 


Accepted Solutions
Solution
‎06-11-2018 02:10 PM
Super User
Super User
Posts: 9,599

Re: proc export lines with spaces at the end

Posted in reply to ger15xxhcker

Well, all I can think of is to put out the data yourself.:

data _null_;
  set x_table;
  file "...abc.txt";
  put vara $141. varb $50...;
run;

Whether that puts spaces at the end, you would have to check, don't see why it should matter however, 

abc     $

abc$

With $ being the end of line, are exactly the same?

View solution in original post


All Replies
Super User
Posts: 10,787

Re: proc export lines with spaces at the end

Posted in reply to ger15xxhcker

I am not sure .

 

filename x "C:\temp\sample.xt" lrecl=200;

proc export
data=x_table
outfile=x
dbms=tab replace ;
putnames=no;
run;
Occasional Contributor
Posts: 6

Re: proc export lines with spaces at the end

thanks but it doesn't work :/

Super User
Super User
Posts: 9,599

Re: proc export lines with spaces at the end

Posted in reply to ger15xxhcker

Sorry, your post makes no sense.  Why are you call executing something with no changes to the code:

proc export data=x_table outfile="C:\temp\sample.xt" dbms=tab replace;
  putnames=no;
run;

Is exactly the same?

Also, what is an xt file?  Maybe a typo.  

Please clarify what you mean by "after the i need spaces until that i reach the $141. length)" as adding in spaces after the end of the data makes no sense, there is nothing after XYZ to indicate the string stops?

Occasional Contributor
Posts: 6

Re: proc export lines with spaces at the end

Sorry for my wording. I attached 2 file. The "bad" one is the actual state. The "good" one is what i want to make.

 

1. I have one table with 1 columns this column length is $141. (x_table)

2. I have to export to a txt file. 

3. If i use this code I get the good.txt file:

proc export data=x_table outfile="C:\temp\sample.txt" dbms=tab replace; putnames=no;run;  (line(s) ending with linebrake instead of spaces)

 

so if i have in a table a $100. length line in the output .txt file have to take +41 spaces to fill the line.

 

soory for my bad english.

 

Thanks for your help!

Gergő 

 

Solution
‎06-11-2018 02:10 PM
Super User
Super User
Posts: 9,599

Re: proc export lines with spaces at the end

Posted in reply to ger15xxhcker

Well, all I can think of is to put out the data yourself.:

data _null_;
  set x_table;
  file "...abc.txt";
  put vara $141. varb $50...;
run;

Whether that puts spaces at the end, you would have to check, don't see why it should matter however, 

abc     $

abc$

With $ being the end of line, are exactly the same?

Occasional Contributor
Posts: 6

Re: proc export lines with spaces at the end

[ Edited ]

Yes, 

abc     $

abc$       is the same. Just i have to put spaces after "abc" until i reach the 141. place.  How can i code this problem?

 

Thanks

Super User
Posts: 13,583

Re: proc export lines with spaces at the end

Posted in reply to ger15xxhcker

@ger15xxhcker wrote:

Sorry for my wording. I attached 2 file. The "bad" one is the actual state. The "good" one is what i want to make.

 

1. I have one table with 1 columns this column length is $141. (x_table)

2. I have to export to a txt file. 

3. If i use this code I get the good.txt file:

proc export data=x_table outfile="C:\temp\sample.txt" dbms=tab replace; putnames=no;run;  (line(s) ending with linebrake instead of spaces)

 

so if i have in a table a $100. length line in the output .txt file have to take +41 spaces to fill the line.

 

soory for my bad english.

 

Thanks for your help!

Gergő 

 


Line "length" is kind of a hazy concept when using dbms=TAB as tab characters are variable in appearance depending upon the viewing program.

 

I am not sure I really understand the problem but perhaps using an appropriate LRECL and RECFM=F such as

 

filename outfl ="C:\temp\sample.txt" lrecl=141 recfm=F;

and use in your output:

proc export data=x_table outfileoutfl dbms=tab replace; putnames=no;run;

 

In a data step LRECL plus the PAD option should also write blanks to the desired length.

Occasional Contributor
Posts: 6

Re: proc export lines with spaces at the end

[ Edited ]

Thanks for your help, but now all of the datas in my table will be one line on the out file txt.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 102 views
  • 0 likes
  • 4 in conversation