The SAS Output Delivery System and reporting techniques

Conditional Formatting

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Conditional Formatting

Hi All,

    I have a column (V_04) in a table, which is character. It has both charater values as well numberic values.

I want to print the values in excel for that coulmn in two different formats, for character value it should be $50. and numeric value it should be commax12.2 format.

 

I have used the below code. but it is not giving the expected value, that is commax12.2

 

compute V_04;

If FMT="N" then do;

call define(_COL_,'format','commax12.2');

end;

else do;

call define(_COL_,'format','$50.');

end;

endcomp;

 

Could you help me to solve this issue.

 

Thanks you.

 

Regards,

Alex

 

 

 


Accepted Solutions
Solution
‎08-23-2016 02:50 AM
SAS Super FREQ
Posts: 8,820

Re: Conditional Formatting

Also, Excel may or may not respect your SAS format when you open the file. You do not indicate how you are creating output for Excel -- ODS EXCEL, ODS TAGSETS.EXCELXP, ODS CSV, or ODS HTML. You can use Microsoft formats to tailor how the rows will be formatted once opened in Excel.

For ODS TAGSETS.EXCELXP or ODS EXCEL, you might use the TAGATTR= style override. For HTML-based output, you might use the HTMLSTYLE= style override. It really depends. There is a longer explanation in this paper:
https://support.sas.com/resources/papers/proceedings11/266-2011.pdf
cynthia

View solution in original post


All Replies
Super User
Posts: 7,444

Re: Conditional Formatting

[ Edited ]

You cannot apply a numerical format to a character variable.

I suggest to convert prior to printing:

if FMT = 'N' then V_04 = put(input(V_04,best.),commax12.2);

Then V_04 can simply be printed as is.

 

Edit: corrected mistake about _COL_

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,720

Re: Conditional Formatting

In any structured environment, columns are treated as all retaining the same format.  Unfortunately Excel is not a structured enironment.  The question is, do you really want mixed formats in one column - from a programmers point of view the response is no.  Reformat your output so that each column has a consistent format.

Solution
‎08-23-2016 02:50 AM
SAS Super FREQ
Posts: 8,820

Re: Conditional Formatting

Also, Excel may or may not respect your SAS format when you open the file. You do not indicate how you are creating output for Excel -- ODS EXCEL, ODS TAGSETS.EXCELXP, ODS CSV, or ODS HTML. You can use Microsoft formats to tailor how the rows will be formatted once opened in Excel.

For ODS TAGSETS.EXCELXP or ODS EXCEL, you might use the TAGATTR= style override. For HTML-based output, you might use the HTMLSTYLE= style override. It really depends. There is a longer explanation in this paper:
https://support.sas.com/resources/papers/proceedings11/266-2011.pdf
cynthia
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 619 views
  • 2 likes
  • 4 in conversation