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
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_
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.