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

Boa Tarde Pessoal!

 

Estou precisando validar se o valor contido em determinada variável é do tipo inteiro, no Python, eu utilizo a operação com módulo (%), contudo, no SAS não rodou, alguém têm alguma dica?

1 ACCEPTED SOLUTION

Accepted Solutions
cepmiranda
SAS Employee

Olá.

Creio que pode usar a função INT:

data RxJunior;
input valor;

if valor ^= int(valor) then Verifica='não inteiro'; *<---Verificando (sim ou ao);
else verifica='interiro';

valor_int=int(valor); *<--- convertendo;

cards;
100
101.10
102
105.86
;
run;

Retirei a ideia de uma resposta das communities:

General SAS Programming
SAS Function to check whether the field value is decimal or numeric

https://communities.sas.com/t5/General-SAS-Programming/SAS-Function-to-check-whether-the-field-value...


A documentação da função INT é a seguinte:

INT Function

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1b1zd0wuyufp0n1jbqlr27p4ea...


Mas, caso queira seguir o raciocínio de resto de divisão, também há a função MOD no SAS:

data test; set RxJunior;
if mod(valor, 1)^=0 then verifica2='não inteiro';
run;

Espero que isso já lhe ajude.

 

View solution in original post

1 REPLY 1
cepmiranda
SAS Employee

Olá.

Creio que pode usar a função INT:

data RxJunior;
input valor;

if valor ^= int(valor) then Verifica='não inteiro'; *<---Verificando (sim ou ao);
else verifica='interiro';

valor_int=int(valor); *<--- convertendo;

cards;
100
101.10
102
105.86
;
run;

Retirei a ideia de uma resposta das communities:

General SAS Programming
SAS Function to check whether the field value is decimal or numeric

https://communities.sas.com/t5/General-SAS-Programming/SAS-Function-to-check-whether-the-field-value...


A documentação da função INT é a seguinte:

INT Function

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1b1zd0wuyufp0n1jbqlr27p4ea...


Mas, caso queira seguir o raciocínio de resto de divisão, também há a função MOD no SAS:

data test; set RxJunior;
if mod(valor, 1)^=0 then verifica2='não inteiro';
run;

Espero que isso já lhe ajude.