BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ger15xxhcker
Quartz | Level 8

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!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

8 REPLIES 8
Ksharp
Super User

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;
ger15xxhcker
Quartz | Level 8

thanks but it doesn't work 😕

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

ger15xxhcker
Quartz | Level 8

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ő 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

ger15xxhcker
Quartz | Level 8

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

ballardw
Super User

@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.

ger15xxhcker
Quartz | Level 8

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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