SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Best practices for setting formats and informats? +ODS question

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Best practices for setting formats and informats? +ODS question

1) Can someone please direct me to a source where I can learn "best practices" for setting suitable formats and informats?

2) Is it correct that ODS MARKUP is the ideal way to format a .CSV-file? I only want to set basic column width and headers for the Excel report.

Thanks.


Accepted Solutions
Solution
‎09-16-2012 09:33 PM
SAS Super FREQ
Posts: 8,744

Re: Best practices for setting formats and informats? +ODS question

Hi:

  Not sure about #1, what you mean by "suitable" formats and informats. I have always found my formats and informats to be dictated by 2 things:

1) input task (reading a data file into a SAS data set or creating informats for data transformation purposes) (INFORMATS)

2) display task (displaying my data for reporting purposes or creating formats for data transformation purposes) (FORMATS)

  But for #2 -- ODS CSV, ODS CSVALL and ODS TAGSETS.CSVBYLINE are 3 ODS MARKUP destinations that allow you to create CSV files from SAS procedure output (such as a PROC PRINT of a SAS dataset or directly from one of your other SAS procedures). However, ODS is not the -only- way to create CSV files. PROC EXPORT can create a CSV file from a SAS dataset. You could write a DATA step program to create a CSV file from a SAS dataset and/or you could look for some older macro programs and tools, like the older %DS2CSV macro program.

  However, you said that you want to set "basic column width and headers for the Excel report" -- CSV -- whether you use PROC EXPORT or ODS -- has NO way to set column widths, no way to set any header attributes beyond using the variable name or variable label.

  If you wanted to explicitly set column widths and/or colors or fonts, you would have to use other ODS destinations, such as ODS MSOFFICE2K and/or ODS TAGSETS.EXCELXP. These two destinations are also ODS MARKUP destinations. In fact, any ODS destination that creates explicit "markup language" output, such as ODS HTML, ODS, MSOFFICE2K, ODS CSV, ODS LaTeX, ODS PHTML, ODS CHTML, ODS TAGSETS.EXCELXP etc, etc are ALL ODS MARKUP destinations. Using ODS MARKUP is a great way to create markup language result files by just changing the tagset template that's used by the destination.

  See the code and screenshot below for an example of setting width for a LONG column value. The NEWNAME variable is rather long and you can see in the CSV file that a default column width is used by Excel when the CSV file is opened. There is different behavior with ODS MSOFFICE2K and ODS TAGSETS.EXCELXP because the CELLWIDTH style override is used by Excel when it opens the XML file (created by TAGSETS.EXCELXP) or the HTML file (created by ODS MSOFFICE2K). And, for an extra wow factor, I change the header colors with a style override too.

cynthia

data class;

  length newname $80;

  set sashelp.class;

  newname = catx(' ',name,repeat(substr(name,1,2),7));

  newname = propcase(newname);

run;

 

** ODS MSOFFICE2K is really making an HTML file;

** but we want to open it with Excel so give it an XLS file extension;

** ODS TAGSETS.EXCELXP is making an XML file, but Excel 2003 and higher;

** knows how to open this XML file.;

ods tagsets.excelxp file='c:\temp\xp.xml' style=sasweb;

ods msoffice2k file='c:\temp\mso.xls' style=sasweb;

ods csv file='c:\temp\comma.csv';

 

proc print data=class noobs

  style(header)={background=pink foreground=black};

  var newname /style(data)={cellwidth=2.5in};

  var name age height weight;

run;

 

ods _all_ close;


make_file_for_excel.png

View solution in original post


All Replies
Respected Advisor
Posts: 3,900

Re: Best practices for setting formats and informats? +ODS question

Do you want to use DI Studio for this?

Solution
‎09-16-2012 09:33 PM
SAS Super FREQ
Posts: 8,744

Re: Best practices for setting formats and informats? +ODS question

Hi:

  Not sure about #1, what you mean by "suitable" formats and informats. I have always found my formats and informats to be dictated by 2 things:

1) input task (reading a data file into a SAS data set or creating informats for data transformation purposes) (INFORMATS)

2) display task (displaying my data for reporting purposes or creating formats for data transformation purposes) (FORMATS)

  But for #2 -- ODS CSV, ODS CSVALL and ODS TAGSETS.CSVBYLINE are 3 ODS MARKUP destinations that allow you to create CSV files from SAS procedure output (such as a PROC PRINT of a SAS dataset or directly from one of your other SAS procedures). However, ODS is not the -only- way to create CSV files. PROC EXPORT can create a CSV file from a SAS dataset. You could write a DATA step program to create a CSV file from a SAS dataset and/or you could look for some older macro programs and tools, like the older %DS2CSV macro program.

  However, you said that you want to set "basic column width and headers for the Excel report" -- CSV -- whether you use PROC EXPORT or ODS -- has NO way to set column widths, no way to set any header attributes beyond using the variable name or variable label.

  If you wanted to explicitly set column widths and/or colors or fonts, you would have to use other ODS destinations, such as ODS MSOFFICE2K and/or ODS TAGSETS.EXCELXP. These two destinations are also ODS MARKUP destinations. In fact, any ODS destination that creates explicit "markup language" output, such as ODS HTML, ODS, MSOFFICE2K, ODS CSV, ODS LaTeX, ODS PHTML, ODS CHTML, ODS TAGSETS.EXCELXP etc, etc are ALL ODS MARKUP destinations. Using ODS MARKUP is a great way to create markup language result files by just changing the tagset template that's used by the destination.

  See the code and screenshot below for an example of setting width for a LONG column value. The NEWNAME variable is rather long and you can see in the CSV file that a default column width is used by Excel when the CSV file is opened. There is different behavior with ODS MSOFFICE2K and ODS TAGSETS.EXCELXP because the CELLWIDTH style override is used by Excel when it opens the XML file (created by TAGSETS.EXCELXP) or the HTML file (created by ODS MSOFFICE2K). And, for an extra wow factor, I change the header colors with a style override too.

cynthia

data class;

  length newname $80;

  set sashelp.class;

  newname = catx(' ',name,repeat(substr(name,1,2),7));

  newname = propcase(newname);

run;

 

** ODS MSOFFICE2K is really making an HTML file;

** but we want to open it with Excel so give it an XLS file extension;

** ODS TAGSETS.EXCELXP is making an XML file, but Excel 2003 and higher;

** knows how to open this XML file.;

ods tagsets.excelxp file='c:\temp\xp.xml' style=sasweb;

ods msoffice2k file='c:\temp\mso.xls' style=sasweb;

ods csv file='c:\temp\comma.csv';

 

proc print data=class noobs

  style(header)={background=pink foreground=black};

  var newname /style(data)={cellwidth=2.5in};

  var name age height weight;

run;

 

ods _all_ close;


make_file_for_excel.png
Frequent Contributor
Posts: 89

Re: Best practices for setting formats and informats? +ODS question

Couldn't have asked for a better answer than that. Thanks Cynthia, very informative.

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 697 views
  • 1 like
  • 3 in conversation