Desktop productivity for business analysts and programmers

How to set the length of variable name to 8 in ODS

Reply
New Contributor
Posts: 2

How to set the length of variable name to 8 in ODS

Dear friends,

How to set the length of variable name to 8 when using ODS to generate output dataset?

Your help will be appreciated!

Gary
SAS Super FREQ
Posts: 8,814

Re: How to set the length of variable name to 8 in ODS

Hi:
I'm confused about what you mean. Do you mean using the ODS OUTPUT statement to create a SAS dataset -- and you want the resulting variable names to only be 8 characters? So, for example, if you used ODS OUTPUT with PROC MEANS, one of the created variables might be SALES_MEAN -- which is NOT 8 characters. If this is what you mean, then you might have to change the code generated in EG to use a RENAME option to rename SALES_MEAN to something like SALE_AVG.

You might be also be referrring to a usage of ODS to create another type of file (CSV, HTML, etc) -- that I have heard some folks refer to as a dataset although it is not a SAS dataset -- and you want the column headers in the resulting file to be only 8 characters?

So depending on what you mean -- you'd either use RENAME for the ODS OUTPUT scenario or some other technique if you were creating a CSV or HTML file.

cynthia
New Contributor
Posts: 2

Re: How to set the length of variable name to 8 in ODS

Hi:

I was talking about the first scenario: I want the variable names (in the dataset created by ODS OUTPUT) to be <= 8 characters long.
There is a cute method. But I do not remember the method.

Thanks,

Gary
SAS Super FREQ
Posts: 8,814

Re: How to set the length of variable name to 8 in ODS

Hi, Gary:
Here's an example you can try in a code node. The RENAME= dataset option will allow you to do the rename right in the ODS OUTPUT statement. Do pay attention to the bunches of parentheses that all have to be matched up.

If you examine the PROC CONTENTS output, you will see that the variable names have been changed.

cynthia

[pre]
** Default names longer than 8 characters;
ods output summary=work.sum_default;
proc means data=sashelp.shoes min mean max sum std;
var sales;
class region;
run;

proc contents data=work.sum_default;
title 'Default Var Names from ODS OUTPUT';
run;

** Use RENAME= to change;
** RENAME= syntax is ;
** dataset-name(rename=(bad_var_name=good_var_name bad_var_name2=good_var_name2));

ods output summary=work.sum_change(rename=(Sales_Max=Sale_Max
Sales_StdDev=Sale_Std
Sales_Sum=Sale_Sum
Sales_Min=Sale_Min
Sales_Mean=Sale_Avg));
proc means data=sashelp.shoes min mean max sum std;
var sales;
class region;
run;

proc contents data=work.sum_change;
title 'After Using the RENAME option';
run;
[/pre]
N/A
Posts: 0

Re: How to set the length of variable name to 8 in ODS

I can't identify any current data manipulation package that wants 8-byte variable names Cynthia, so I wondered why this would be needed. However, my first thought was that SAS might have coded some backward compatibility into a system option, and I went looking at ValidVarName to see whether it had a V6 option available.

Sadly, the documentation doesn't report anything other than V7, UPCASE and ANY. Still, that would have been an easy solution.

Kind regards

David
SAS Super FREQ
Posts: 8,814

Re: How to set the length of variable name to 8 in ODS

David:
Actually, that IS a brilliant idea (it has a downside -- but still brilliant).

VALIDVARNAME=V6 is a possible option. It was designed so that "VALIDVARNAME=V6 indicates that only those variable names that are considered valid in Version 6 are considered valid SAS variable names.", then THIS does work:
[pre]
options validvarname=V6;
** Default names longer than 8 characters;
ods output summary=work.sum_default;
proc means data=sashelp.shoes min mean max sum std;
var returns;
class product;
run;

proc contents data=work.sum_default;
title 'Default Var Names from ODS OUTPUT';
run;

[/pre]

BUT, the downside of this approach is that the INVENTORY variable is on SASHELP.SHOES. So with the VALIDVARNAME=V6 option set,
then INVENTORY is NOT a valid name. So in that case, you'd have to use the RENAME= option. In the long run, I think RENAME= might be the best way to go because it will work under all situations -- and you don't then have to worry about your V8 and V9 datasets with longer variable names (which you might want to use for analysis).

Great idea!

cynthia
N/A
Posts: 0

Re: How to set the length of variable name to 8 in ODS

I made a newbie mistake then Cynthia. I expected that the documentation would be complete, which was a poor assumption. I thought as a Developer, and decided that would be a valid option, but when I checked the book of words, it wasn't there.

I should have tested it, as I intended to, but time and other demands got in the way. Your point on the table name is well taken, and it wasn't a problem I envisaged because I assumed that wanting 8-byte column names also meant table names would conform to the same requirement. Not good; two bad assumptions in one day .

So the lesson is: not to assume and to test your ideas.

Kind regards

David
Ask a Question
Discussion stats
  • 6 replies
  • 114 views
  • 0 likes
  • 3 in conversation