BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

Dear all,

I have a question I have a dataset exported from postgresql and there are columns containing whole numbers as well as decimal numbers. The decimals numbers are seperated with periods (e.g. 0.166)

and the whole numbers are like 50, 75, 100 etc. These values are imported into SAS with format best12. I wish to change the period to comma like 0.166 should be 0,166

 

I tried using this code:

option locale = de_DE;
data xyz;
data want;
format ab commax7.2;
run;

That works well, my question is, is it possible to make SAS only set the decimal numbers to 2 decimal places? The whole numbers like 50, 75 should not be written as 50,00 or 75,00

I guess this is not possible but there might be a way to work around this.

 

The column should remain like in the original data only the period should be replaced with a comma

Thanks 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

If you want to use PROC REPORT to create an output table with these formats, yes it is possible. 

 

I think you can also use PROC FCMP to create a function used as a format, see https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=proc&docsetTarget=p1gg77j...

--
Paige Miller
Ksharp
Super User
proc fcmp outlib=work.func.math;
function x(x) $;
 length result $ 40;
 if mod(x,1)=0 then result=left(put(x,best32.));
  else result=left(put(x,commax32.2 ));
  return (result);
endsub;
run;

options cmplib=work.func;
proc format ;
picture fmt
low-high=[x()];
run;

data x;
input x;
format x fmt10.;
cards;
73.21
65
;

I am not sure I understood what you are looking for.

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
  • 396 views
  • 4 likes
  • 3 in conversation