Kanan Mehdizade
Kanan Mehdizade

Reputation: 73

Cannot implement if then logic to sql code

Wanted to change the SAS code to SQL, but did not know which way should I follow, but I tried with case when, it gave me error.

SAS Code:

length list_of_Fields $400.;
list_of_Fields = "";

if missing(column_a)        eq 1 then do; if calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company1"); calc_of_count + 1; end;
if missing(column_b)        eq 1 then do; if calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company2"); calc_of_count + 1; end;


if list_of_Fields eg "" then list_of_Fields = &strNone

SQL CODE:

case 
    when column_a is null then case when calc_of_count <= limit_of_Count then ist_of_Fields = catx(" ;", calculation_of_columnName, "Company1") 
    when column_b is null then case when calc_of_count <= limit_of_Count then list_of_Fields = catx(" ;", calculation_of_columnName, "Company2") 

Unfortunately was not able to finish it accordingly, could you please help me to find the way?

Upvotes: 0

Views: 90

Answers (1)

Chella
Chella

Reputation: 1562

You can do that in the following way:

CASE 
    WHEN (column_a is null AND calc_of_count <= limit_of_Count) THEN ist_of_Fields = CONCAT(" ;", calculation_of_columnName, "Company1") 
    WHEN (column_b is null AND calc_of_count <= limit_of_Count) THEN list_of_Fields = CONCAT(" ;", calculation_of_columnName, "Company2") 
    ELSE list_of_Fields = &strNone
END

You can also try IF CLAUSE in below format:

IF(condn, TRUE_STATEMENT, FALSE_STATEMENT);

Upvotes: 1

Related Questions