put() uses a format, input() uses an informat. Your method is the correct way to do it.
In terms of the syntax you did it correctly. However, if you started with extremely large values, you may not have converted properly.
SAS formats specify the entire width. For example, 15.2 does NOT mean 15 digits before the decimal point, plus 2 digits after. It means a total of 15 characters including digits before the decimal point, digits after, and the decimal point itself. It also includes a negative sign if one is needed.
If your data actually contains numbers as large as 1 trillion, then the width of 15 would not be enough when using a dollar15.2 format. This number requires a width of 17:
$1,222,333,444.00
The original format of 15.2 makes me think that you might need a width of 15 without the commas and dollar sign. If that is the case, you would need a wider format when adding commas and a dollar sign, such as dollar19.2
If you just want to display the variable AMT as a dollar sign plus some numbers, assign a format to it. No need to create a new variable.
I agree with @PaigeMiller that there is likely very little reason to create a character variable for most uses. One real reason not to is that values do not sort as expected.
data example; length x $ 15; x="$39.54";output; x="$1,000,000.00"; output; run; proc sort data=example; by x; run; proc print data=example; run;
which would imply that a million is less than 39.
You could end up spending a lot of time playing with output to get things to appear the way you want in report and analysis procedures.
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.