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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 623 views
  • 1 like
  • 2 in conversation