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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

6 REPLIES 6
Astounding
PROC Star

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?

atul_desh
Quartz | Level 8

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

PeterClemmensen
Tourmaline | Level 20

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.

Cynthia_sas
SAS Super FREQ

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???

not_understand_scan.png

 

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

Ksharp
Super User

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;
atul_desh
Quartz | Level 8
Thank you so much.... 🙂

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1953 views
  • 0 likes
  • 5 in conversation