DATA Step, Macro, Functions and more

Help with a Tab Delimeted File using Put

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Help with a Tab Delimeted File using Put

Help!!  I need to create a Tab Delimeted File with several blank columns and a final column that is the concatenation of 6 vars I am having 2 issues:

 

1. even though I have coded a Tab , the output also has a Comma Delimeter

2. I need to get rid of the blank space after the variable and before the text

 

Here is my code and I am attaching the output and a small sasfile i am testing with:

 
data _null_;
  set lago;
  tabdlm='2C'x;
  file out1 lrecl=32767;
  put
   '123456'tabdlm
   sku tabdlm
   'D31720' tabdlm
   description tabdlm 
   tabdlm 
   tabdlm 
   tabdlm 
   tabdlm 
   tabdlm 
   tabdlm           
   tabdlm           
   tabdlm           
   tabdlm           
   tabdlm           
   'croas=' croas 
   '\units=' units 
   '\demand=' ___K_s_
   '\woos=' wk_OOS 
   '\categ=' categ 
   '\yoi=' yrs_inv
 ;
run;

Accepted Solutions
Solution
‎08-15-2017 06:36 PM
Super User
Posts: 5,516

Re: Help with a Tab Delimeted File using Put

Taking your questions in order ...

 

You didn't ask for a tab.  You asked for a comma.  2C is the hex code for a comma.  Off the top of my head, 09 is the hex code for a tab, but you'll have to check that.  If that's correct, use   tabdlm='09'x;

 

When the PUT statement encounters a variable name without a format, it leaves a single blank after the variable's value.  You have to tell SAS to back up, and write over that single space:

 

put '123456'  tabdlm +(-1)  sku +(-1) tabdlm +(-1)      etc.;

 

For constant text, such as "123456" there is no extra blank so don't add +(-1) there.

 

For safety's sake, leave a space after closing quotes.  A "t" immediately following a closed quote has the potential to cause problems.

 

That should do it.  Good luck.

View solution in original post


All Replies
Super User
Posts: 19,861

Re: Help with a Tab Delimeted File using Put

Contributor
Posts: 43

Re: Help with a Tab Delimeted File using Put

Well I have egg on my face over that one!   yes i had the comma not the tab -ugh...   Thank you for seeing the obvious because for the life of me I couldn't Smiley Happy

Solution
‎08-15-2017 06:36 PM
Super User
Posts: 5,516

Re: Help with a Tab Delimeted File using Put

Taking your questions in order ...

 

You didn't ask for a tab.  You asked for a comma.  2C is the hex code for a comma.  Off the top of my head, 09 is the hex code for a tab, but you'll have to check that.  If that's correct, use   tabdlm='09'x;

 

When the PUT statement encounters a variable name without a format, it leaves a single blank after the variable's value.  You have to tell SAS to back up, and write over that single space:

 

put '123456'  tabdlm +(-1)  sku +(-1) tabdlm +(-1)      etc.;

 

For constant text, such as "123456" there is no extra blank so don't add +(-1) there.

 

For safety's sake, leave a space after closing quotes.  A "t" immediately following a closed quote has the potential to cause problems.

 

That should do it.  Good luck.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 97 views
  • 5 likes
  • 3 in conversation