data a;
input l $10.;
cards;
111.0000
1.0
0.00
0.000
0
22.120
262.100
run;
required output
111
1.0
0.00
0.0000
0
22.120
262.1
What is the logic here? l is a character value, correct? Do you want the desired result to be character too?
If you don't know what problem to solve, neither do we 🙂
Code is built on a logical specification. Without a logical rule for getting from A to B, nobody can do anything.
There is no (for me) discernible pattern in the data you gave us.
Can you go back to the person who asked you to do this work and ask them, what are the rules that change "111.0000" to "111", "1.0" to "1.0" (same), ..., "262.100" to "262.1"?
Does the rule change based on the input value?
Does the number of non-zero digits affect the rules?
etc.
Then you can share the rules here and someone should be able to help if you still have problems.
If you get the solution yourself then please share that here too.
Amir.
Hi @rajeshalwayswel,
It appears that you want to apply a conditional format, i.e., one that depends on certain rules. So, maybe the PUTN function can be applied. But, as the others have pointed out, you need to know those "certain rules."
Here are two examples using rather arbitrary rules both of which produce the desired values (in a character variable W in dataset WANT) for your sample data using the w.d format with a varying value of d and left-justified by the -l modifier.
data want;
array d[7] _temporary_ (0,1,2,4,0,3,1);
set a;
length w $10;
w=putn(input(l,10.),cats('10.',d[_n_],'-l'));
run;
data want;
set a;
length w $10;
w=putn(input(l,10.),cats('10.',ranpoi(1382551861,2),'-l'));
run;
If you need the formatted value just for output (e.g. to a text file), the $VARYINGw. format might be useful.
Example (similar to no. 1 above, but now the lengths are pre-specified and the results are written to the log😞
data _null_;
array len[7] _temporary_ (3,3,4,6,1,6,5);
set a;
w=put(input(l,10.),10.4-l);
varlen=len[_n_];
put w $varying10. varlen;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.