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

Olá pessoal! Estou estudando curso SAS Programming I: Essentials e uma das aulas me deixou com a pulga atrás da orelha. Nos foi apresentado o código abaixo para mostrar como funciona o fluxo da condição, porém minha querida professora Stacey disse o seguinte sobre o código, no vídeo e na descrição:

 

The last assignment statement determines the value of PressureGroupo when MinPressure is missing

data storm_new;
	set pg1.storm_summary;
	keep Season Name Basin MinPressure PressureGroup;
	if MinPressure =. then PressureGroup=.;
	if MinPressure <= 920 then PressureGroup=1;
	if MinPressure > 920 then PressureGroup=0;
run;

Resumidamente na aula ela disse que a última instrução é que determina o valor da coluna PressureGroup quando o valor de MinPressure é missing. 

 

A primeira condição atribui corretamente um ponto à coluna quando o valor da expressão for missing, até aí tudo certo. A segunda condição sobrescreve o valor atribuído na condição anterior, fazendo com que os valores missing assumissem o valor 1, pois missing é menor que o valor procurado. No entanto, o trecho diz "The last" ou seja, a última expressão é quem irá determinar o valor da coluna quando a condição for igual a missing.

 

img1.png

 

Observando a tabela de resultado, se a última expressão determina o valor da coluna quando a condição é missing, porque tanto os valores abaixo de 920 quanto os missing estão com valor 1 na coluna PressureGroup? Para que esta afirmação seja verdadeira o valor de missing para PressureGroup não deveria ser 0, segundo a afirmação?

 

Para tentar entender melhor minha questão deixo um arquivo no formato PDF com alguns detalhes para melhor compreensão da questão.

 

Desde já agradeço pela atenção e ajuda!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

A missing value is per definition lower than any non-missing value, so for missing values the second condition overrides the first:

if MinPressure =. then PressureGroup=.;
if MinPressure <= 920 then PressureGroup=1;

To avoid this, use else if:

if MinPressure =. then PressureGroup=.;
else if MinPressure <= 920 then PressureGroup=1;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

A missing value is per definition lower than any non-missing value, so for missing values the second condition overrides the first:

if MinPressure =. then PressureGroup=.;
if MinPressure <= 920 then PressureGroup=1;

To avoid this, use else if:

if MinPressure =. then PressureGroup=.;
else if MinPressure <= 920 then PressureGroup=1;
DaniloTrindade
Fluorite | Level 6

Perfect, but the problem is not sintaxe or knowladge of the conditional if-then/else, the question is about the information apresented into course. In this code the teacher said that the last assignment statement determines the value of the new column. This actually happens if you just use the if conditional.

 

if MinPressure =. then PressureGroup=.;
if MinPressure <= 920 then PressureGroup=1;
if MinPressure > 920 PressureGroup=0;

 

I could be use this conditions to resolve this problem

if MinPressure =. then PressureGroup=.;
else if MinPressure <= 920 then PressureGroup=1;
else PressureGroup=0;

So, thank you very much for your help.