DATA Step, Macro, Functions and more

sas variable names with spaces

Reply
Occasional Contributor
Posts: 6

sas variable names with spaces

is there a way to export sas variables to excel via dde when the variable names contain spaces? eg. put 'reporting month'n 'claim count'n. I have explored every idea using '09'x and @ and formats with the put statement but all failed.
Super User
Posts: 19,815

Re: sas variable names with spaces

Include the NOTAB option in your file statement and you shouldn't have a problem. 

 

If you do, post your code. 

Occasional Contributor
Posts: 6

Re: sas variable names with spaces

It makes no difference. The notab option is included in both the filename
and file.

Filename xl dde "&xlfile." notab lrecl =2500;
Data _null_; set dat ; file xl notab; /* with or without */
If _n_ = 1 then put 'report month'n 'claim count'n;

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Trusted Advisor
Posts: 1,117

Re: sas variable names with spaces

It looks like you want to write those variable names as column headers to the Excel table. In this case the name literals don't make sense. Please try this:

if _n_ = 1 then put 'report month' '09'x 'claim count';

If something doesn't work, please provide more details (log messages, the output you get, ...)

Occasional Contributor
Posts: 6

Re: sas variable names with spaces

[ Edited ]
Posted in reply to FreelanceReinhard
as i said previously, all ideas with '09'x, notab, @ etc were considered and all failed. there's no error in the log except that variables are not unitialised message due to spaces in variable names. here's a simple dataset for you to experiment on with the aim of writing it to excel. data d; format 'report month'n ddmmyy10.; 'report month'n = "1mar16"d; 'claim count'n = 1; output; 'report month'n = "1apr16"d; 'claim count'n = 2; output; 'report month'n = "1may16"d; 'claim count'n = 3; output; run; please note that I'm aware there are other ways to do this but I need this done using DDE.
Occasional Contributor
Posts: 6

Re: sas variable names with spaces

Posted in reply to FreelanceReinhard
Finally it works! a combination of notab in the fielname statement and the naming of variables as Reeza suggested ie. 'REPORTING MONTH' '09'X 'CLAIM COUNT'; Thank you all.
Super User
Super User
Posts: 7,958

Re: sas variable names with spaces

Don't use DDE - its old (very), and not supported, plus doesn't work on some setups.  Plus you have all the limitations associated with Excel 95.  Why do you need to use it?  Proc export works ok, then there is tagsets.excelxp, which allows a lot of customisation even if it does create XML rather than a native XML XLSX file.  Then there is libname to Excel, then there is CSV, ... in fact there are so many options which are better than DDE.

Super User
Posts: 7,799

Re: sas variable names with spaces

Don't use blanks in variable names. Use the labels for descriptive text, and put those in your output when necessary.

Blanks in identifiers (variable names, file names etc) only cause additional work, make programs less readable and serve no purpose.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 7 replies
  • 543 views
  • 0 likes
  • 5 in conversation