BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Hi Everyone,

Can you please help me to achieve output without any decimal, I have many data , so mainly I need output without decimal. 

Input :

17.921
7.83
379.48
1.040.855
0
1.09
237.703
1.11
4.387

 

Output

17921
783
37948
1040855
0
109
237703
111
4387
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What type of variable is this?  If it is character you can just use the COMPRESS() function to remove the period.

If it is numeric then can you explain why it makes any sense to remove the period? How did the values get recorded with the decimal place in the wrong place to begin with?  It would probably be better to fix it there instead of after the fact.  If you really need to remove the period then it might be easiest to just convert the number to a string and remove the period and then convert the string back into a number.

data want ;
  set have;
  string = compress(string,'.');
  number = input(compress(put(number,best32.),'.'),32.);
run;

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

What type of variable is this?  If it is character you can just use the COMPRESS() function to remove the period.

If it is numeric then can you explain why it makes any sense to remove the period? How did the values get recorded with the decimal place in the wrong place to begin with?  It would probably be better to fix it there instead of after the fact.  If you really need to remove the period then it might be easiest to just convert the number to a string and remove the period and then convert the string back into a number.

data want ;
  set have;
  string = compress(string,'.');
  number = input(compress(put(number,best32.),'.'),32.);
run;

 

Patrick
Opal | Level 21

Given your number 1.040.855 with two dots this looks to me more like the display of a integer that uses dot as thousand separator and comma for decimal like it's common in many European countries.

Because this is likely just about display (print) of numbers a simple change of the format used for display will give you what you want. 

Below to demonstrate what I'm talking about.

%let sv_locale=%sysfunc(getoption(locale,keyword));
options locale=German_Germany;
data have;
  input numvar_1;
  numvar_2=numvar_1;
  numvar_3=numvar_1;
  format numvar_1 nlnum16. numvar_2 nlnum16. numvar_3 best32.;
  datalines;
17921
783
37948
1040855
0
109
237703
111
4387  
;
title 'Print (display) numbers using formats from Have';
proc print data=have;
run;
title 'Print (display) numvar_2 using format best32.';
proc print data=have;
  format numvar_2 best32.;
run;
title 'Print (display) all numerical variable with format best32.';
proc print data=have;
  format _numeric_ best32.;
run;
options &sv_locale;

Patrick_0-1716690908267.png

 

If above doesn't work for you then please share the result of a Proc Contents of your source data so we can understand what data type and format gets used for your values.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 318 views
  • 0 likes
  • 3 in conversation