Buena Tarde,
Como hago para que en la columna "A" tengo la información para calcular, esta cuenta con AÑO, MES, COD RAMO, RAMO, CUENTA FORMATO, NOMBRE, COMPAÑIAS, me gustaría calcular una Columna "B", de la siguiente manera:
CASO
CUANDO t1.A = 0
LUEGO "BUSCAR VALOR ANTERIOR"
CASO
CUANDO t1.MES = 1
LUEGO t1.A
ELSE t1.A
END
END}
AÑO | MES | COD RAMO | RAMO | CUENTA FORMATO | NOMBRE | COMPAÑIAS | Naciones Unidas | segundo |
2017 | 1 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -596842008.2 | -596842008 |
2017 | 2 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -15616722.71 | -15616722.7 |
2017 | 3 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | 0 | -15616722.7 |
2017 | 4 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | 0 | -15616722.7 |
2017 | 5 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | 0 | -15616722.7 |
2017 | 6 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | 0 | -15616722.7 |
2017 | 7 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -2338748.87 | -2338748.87 |
2017 | 8 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | 0 | -2338748.87 |
2017 | 9 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -40651243.2 | -40651243.2 |
2017 | 10 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -999345.29 | -999345.29 |
2017 | 11 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -1388093.24 | -1388093.24 |
2017 | 12 | 11 | hacer | 10999 | TOTAL PARCIAL | METRO | -1994599.5 | -1994599.5 |
Hola @juan94, bienvenido a SAS Support Communities. Yo comprendo español un poco, pero hablamos ingles en este foro.
And...SAS syntax is based in English...
Your pseudocode (using a CASE statement) requires SQL. Is that how you intend to solve this? If so, the form of an SQL CASE statement is:
CASE (term | expression)
WHEN (compare-value | expression) THEN (result-value)
...
END as (target-variable)
So your example would be:
proc sql;
create table target as select *,
case t1.A
when 0 then "BUSCAR VALOR ANTERIOR"
else "default value"
end as new_value1,
case t1.MES
when 1 then t1.A
else t1.A
end as new_value2
from source_table;
quit;
Of course, second expression does not make sense, as it results in the same value whether for any condition of t1.MES (month). I'm not really sure what your objective is here -- but I might have missed something in my poor translation.
If you're new to SAS and using SQL syntax because that's what you're familiar with, I suggest trying with DATA step instead. That approach is much more flexible. Check out this tutorial, How to Write a Basic SAS Program. It's in English, but I think you can turn on captioning and that might help.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.