DATA Step, Macro, Functions and more

How to handle variable names with spaces and more than 32 leangth

Reply
Contributor
Posts: 60

How to handle variable names with spaces and more than 32 leangth

Hi Experts,

 I need to handle variable names with spaces and more than 32 char leangth .

Variable names with spaces- I need to show variable names in excel , the format my client need in this format.

 

Please let me know if there is any way

Super User
Super User
Posts: 7,401

Re: How to handle variable names with spaces and more than 32 leangth

What you need to show then is labels not variable names.  Variable names are for programming, variable labels are for display.  Names are short, minimal characters to enable programming, labels are anything and used for people to read.  You can get your labels out to Excel in any number of ways, ods tagsets.excelxp and proc report is my preferred.  As you haven't shown anything about what you are doing, how you get your output its hard to say.

You can, and I say that very loosely as it is highly recommended not to do this, reference variable names by using named literals:

'a long variable name'n

Note the n afterwards, however again, highly not recommended.  If I saw this in my code it would be removed immediately.

Contributor
Posts: 60

Re: How to handle variable names with spaces and more than 32 leangth

I use the attached macro to export data in to an excel . The template excel will be there in one folder and will call this macro in the job for exporting

%macro exportfile(pathname=, data=); 
libname _lbxls odbc noprompt="dsn=Excel Files; dbq=&pathname"; 

proc datasets lib=_lbxls; 
delete 'Data$'n; 
run; 

proc datasets lib=_lbxls; 
delete Data; 
run; 

proc append 
base=_lbxls.Data 

data=&data; 
run; 

libname _lbxls clear; 
%mend exportfile; 


%macro exportreport(path=, name=, date=, format=, data=); 
data _NULL_; 

src=&path || &name || '.xlsx'; 
src2 = &path || &name || '.xls'; 

dest = &path || &name || ' ' || put(&date, &format) || '.xlsx'; 
dest2 = &path || &name || ' ' || put(&date, &format) || '.xls'; 

if (fileexist(src)) then 
        do; 
                call system('copy ' || quote(src) || ' ' || quote(dest)); 
                call symput('_exportreportpathname', dest); 
        end; 
 else if (fileexist(src2)) then 
        do; 
                call system('copy ' || quote(src2) || ' ' || quote(dest2)); 
                call symput('_exportreportpathname', dest2); 
        end; 

run; 

%exportfile(pathname=&_exportreportpathname., data=&data); 
%mend exportreport;
Super User
Super User
Posts: 7,401

Re: How to handle variable names with spaces and more than 32 leangth

If you already have a template excel file which your sending data to, why do you need variable names/labels, why are they not already in this template Excel file?

Ask a Question
Discussion stats
  • 3 replies
  • 119 views
  • 0 likes
  • 2 in conversation