This is a SAS community, so Teradata knowledge can be limited.
The logic you show is not easy to directly convert to SQL, could be if Teradata have some specific functions/syntax for this.
You might be better off asking in a Teradata forum.
For slightly simpler queries, just use a Teradata libname, it will generate Teradata SQL on the fly (implicit SQL pass through).
Data never sleeps