I want dollar32. format for non-decimnal value. and dollar32.2 for decimal containing value..
I've write below code but its not working as expected.
data ds5;
input var5 32. ;
if scan(var5,2,'.') gt 0 then var5=input(var5,dollar32.2);
else var5=input(var5,dollar32.);
datalines;
625355
856422.54121
818935.584
456464.51
560843.1
558.55
58.00
5
;
run;
Try PROC FCMP + PROC FORMAT .
proc fcmp outlib=work.func.t;
function xx(x) $;
length temp $ 40;
if mod(x,1)=0 then temp=put(x,dollar32.);
else temp=put(x,dollar32.2);
return (temp);
endsub;
run;
options cmplib=work.func;
proc format;
value fmt
low-high=[xx()];
run;
data ds5;
input var5 32. ;
format var5 fmt40.;
datalines;
625355
856422.54121
818935.584
456464.51
560843.1
558.55
58.00
5
;
run;
proc print;run;
You are asking about formats, but showing a program that doesn't use any formats. All of these are informats within the context of your program:
32.
dollar32.
dollar32.2
What is it that you are trying to accomplish as the end result?
I wants value like in want column :
have want
625355 $625,355
856422.5412 $856,422.54
818935.584 $818,935.58
456464.51 $456,464.51
560843.1 $560,843.10
558.55 $558.55
58.00 $58
5 $5
A variable can have no more than 1 format. What you are using here though in your INPUT functions are INformats, which are used to tell SAS how to READ data. not WRITE it.
Hi:
Also, your var5 is a numeric variable. The SCAN function is designed for character variables. So you should be seeing some messages in your log.
It is not clear what you are trying to do. The INPUT function is how you convert a character variable (such as a character string for date or a number with currency) into a number. But you are starting with a number. I don't understand what you're trying to do. Have you even looked at the output from your program without the INPUT???
You do not need different formats for storing the internal value of the variable. Do you want different formats for displaying the value of VAR5 in a report? If so, there are other ways to accomplish that. But what you are doing in your program is not clear.
cynthia
Try PROC FCMP + PROC FORMAT .
proc fcmp outlib=work.func.t;
function xx(x) $;
length temp $ 40;
if mod(x,1)=0 then temp=put(x,dollar32.);
else temp=put(x,dollar32.2);
return (temp);
endsub;
run;
options cmplib=work.func;
proc format;
value fmt
low-high=[xx()];
run;
data ds5;
input var5 32. ;
format var5 fmt40.;
datalines;
625355
856422.54121
818935.584
456464.51
560843.1
558.55
58.00
5
;
run;
proc print;run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.