BookmarkSubscribeRSS Feed
RxJunior
Fluorite | Level 6

Ola pessoal...

 

Estou com uma dúvida simples, porém até agora não localizei como resolver. 

 

No Python e SQL, possuímos o operador (%) para realizar divisões e obter apenas a parte inteira (Módulo), contudo, no SAS, ainda não identifiquei qual operador utilizar.

 

Exemplo:

12%5 = 2

1 REPLY 1
mkeintz
PROC Star

I am not aware of a modulo operator, but there is a modulo function:

 

data _null_;
    z=12;
    x=mod(z,5);
    put (_all_) (=);
run;

 

I should add that the above will be consistent with the % python operator only for positive numbers.

 

If you want faithful replication of the % operator (as described here ) you would apparently need

 

 

     x=mod(z - (5 * floor(z/5);

or more generally

  x=    z - (n * floor(z/n));

   

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------