BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexsander
Fluorite | Level 6

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
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

3 REPLIES 3
Kurt_Bremser
Super User

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_

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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