0
votes

I am working on translating a SAS code to R and since I am new to SAS I am having some trouble understanding data formats in SAS. Also, I don't have access to SAS so i can't try it on a sample data.

My code snippet says -

Data A;
  Set A;
  format Sales_change percent7.4 sales_units comma10.3;
run;

I believe comma10.3 makes the values 'numeric' like the numeric format in excel. i.e. 1000000 becomes 1,000,000. But what does percent7.4 format do? Does it make 0.2364212 as 23.6421% ? If so, I have been using the following line in R -

A$Sales_change <- percent(A$Sales_change/1)

But this rounds of the numbers to 2 decimal places before reporting the percent values. Can someone tell me if my understanding is right and if right, how to do this in R?

1
Extremely sorry. I messed it. I am converting a SAS code to R. - RHelp

1 Answers

2
votes

The documentation for this, like all SAS documentation is on the web -- but in this case it's pretty confusing.

The 7 is the width of the formatted output in characters, including the decimal point, the percent sign, and two characters reserved for parentheses to denote negative values, even if the formatted number is positive. The 4 is the the number of digits to the right of decimal to display (as long as there's room in the overall length).

So here, you get 23.6%. Three digits, plus a decimal point, plus a percent sign, plus space for parentheses equals 7 characters.

(I don't know your exact needs, maybe it's not worth the hassle of emulating SAS's width-based format style in R.)