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;
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.
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 🙂
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.