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

Hi All,

I have a column in dataset which has numeric values. I am converting these numeric values to character using put function.

Like a= put (b,4.);

Now this numeric variable, b can have one decimla place too, like 9.1, 8.2 etc,.

When I apply the format a= put(b,$4.1), SAS appends the decimal distd to even nondecomal mnumbers like

when b = 5 , 6 then a is character 5.0 and 6.0

Now my problem is, I dont want .0 when there is no decimal place int he number.

How can I do that without writing a big code.

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Best is to use TRANWRD to remove the .0. You could try using BEST4.1 format, but it has trouble with numbers that do not fit into decimal fractions (like 1/3).  You could put in a ROUND function call.  What do want to do with 1.999999999 or 1.00000001 ?

285  data _null_;

286    do x=1,3.4,1+1/3;

287      y=put(x,4.1);

288      y2=tranwrd(y,'.0',' ');

289      z=put(x,best4.1);

290      z2=put(round(x,0.1),best4.1);

291      put (_all_) (=);

292

293    end;

294  run;

x=1 y=1.0 y2=1 z=1 z2=1

x=3.4 y=3.4 y2=3.4 z=3.4 z2=3.4

x=1.3333333333 y=1.3 y2=1.3 z=1.33 z2=1.3

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Best is to use TRANWRD to remove the .0. You could try using BEST4.1 format, but it has trouble with numbers that do not fit into decimal fractions (like 1/3).  You could put in a ROUND function call.  What do want to do with 1.999999999 or 1.00000001 ?

285  data _null_;

286    do x=1,3.4,1+1/3;

287      y=put(x,4.1);

288      y2=tranwrd(y,'.0',' ');

289      z=put(x,best4.1);

290      z2=put(round(x,0.1),best4.1);

291      put (_all_) (=);

292

293    end;

294  run;

x=1 y=1.0 y2=1 z=1 z2=1

x=3.4 y=3.4 y2=3.4 z=3.4 z2=3.4

x=1.3333333333 y=1.3 y2=1.3 z=1.33 z2=1.3

maggi2410
Obsidian | Level 7

Hi Tom,

Thanks . Best4.1 works for me coz i don't expect any value with more then 1(or max two decimal places). 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 7451 views
  • 0 likes
  • 2 in conversation