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

I have data like below

data a;

input x;

cards;

1234

54

0.005

0.634

run;

 

I want output as below

 

1234

54

0.00

0.63

 

Can anyone please suggest me

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
Kurt_Bremser
Super User

Define "output".

If you want this kind of behavior in a dataset, you need to create a custom format with a function.

If you want it in a report, consider proc report and a computed column.

Minku
Fluorite | Level 6

I want in data set, can  you please write how to write custom format with function

 

Thanks for your reply

Kurt_Bremser
Super User

See here:

proc fcmp outlib=work.functions.smd;
function myfunc (arg) $;
  if int(arg) = arg
  then out = left(put(arg,best18.));
  else out = left(put(arg,18.2));
  return(out);
endsub;
run;

options cmplib=work.functions;

proc format;
value myfmt (default=18) other=[myfunc()];
run;

data a;
input x;
format x myfmt.;
y = put(x,myfmt.);
cards;
1234
54
0.005
0.634
;

Relevant parts of the documentation:

FUNCTION Statement in PROC FCMP 

PROC FORMAT (Example 20) 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 597 views
  • 1 like
  • 2 in conversation