You will have a much better chance of getting an answer if you present your data as a data step, e.g. like this:
data have;
input Car $ Type $ Engine $ Test_result $;
cards;
Honda Civic Hybrid Ok
Honda Civic Benz Ok
Honda Civic Diesel Nok
Mercedes Cklass Benz Ok
Mercedes Cklass Hybrid Ok
Mercedes Cklass Diesel Ok
Audi a6 Benz Ok
Audi a6 Hybrid Ok
Tesla x Benz Nok
Tesla x Hybrid Nok
Tesla x Diesel Nok
Opel Insigne Hybrid Unknown
Opel Insigne Diesel Unknown
Opel Insigne Benz Ok
Volvo V60 Benz Ok
Volvo V60 Hybrid Nok
Volvo V60 Diesel Nok
Volvo V60 Electric Unknown
Peugeot 5008 Benz Unknown
Peugeot 5008 Hybrid Unknown
Peugeot 5008 Diesel Unknown
;run;
I think you can get the answers you want like this:
data want;
set have;
by car type notsorted;
n_OK+Test_result='Ok';
n_Nok+Test_result='Nok';
n_Unknown+Test_result='Unknown';
if last.type;
if n_Nok then do;
Test_result='Nok';
output;
if n_Unknown then do;
Test_result='Unknown';
output;
end;
end;
else if n_Unknown then do;
Test_result='Unknown';
output;
end;
else do;
Test_result='Ok';
output;
end;
call missing(of n_:);
drop engine;
run;
Notes:
n_OK+Test_result='Ok'
) automatically retain the result variables.But I do not think your specification of results is consistent. On one hand, your output table has two records for the Volvo, but in the final sum-up you apparently only count the "Nok" record (otherwise, there should be 3 types that are "also Unknown").
You will have a much better chance of getting an answer if you present your data as a data step, e.g. like this:
data have;
input Car $ Type $ Engine $ Test_result $;
cards;
Honda Civic Hybrid Ok
Honda Civic Benz Ok
Honda Civic Diesel Nok
Mercedes Cklass Benz Ok
Mercedes Cklass Hybrid Ok
Mercedes Cklass Diesel Ok
Audi a6 Benz Ok
Audi a6 Hybrid Ok
Tesla x Benz Nok
Tesla x Hybrid Nok
Tesla x Diesel Nok
Opel Insigne Hybrid Unknown
Opel Insigne Diesel Unknown
Opel Insigne Benz Ok
Volvo V60 Benz Ok
Volvo V60 Hybrid Nok
Volvo V60 Diesel Nok
Volvo V60 Electric Unknown
Peugeot 5008 Benz Unknown
Peugeot 5008 Hybrid Unknown
Peugeot 5008 Diesel Unknown
;run;
I think you can get the answers you want like this:
data want;
set have;
by car type notsorted;
n_OK+Test_result='Ok';
n_Nok+Test_result='Nok';
n_Unknown+Test_result='Unknown';
if last.type;
if n_Nok then do;
Test_result='Nok';
output;
if n_Unknown then do;
Test_result='Unknown';
output;
end;
end;
else if n_Unknown then do;
Test_result='Unknown';
output;
end;
else do;
Test_result='Ok';
output;
end;
call missing(of n_:);
drop engine;
run;
Notes:
n_OK+Test_result='Ok'
) automatically retain the result variables.But I do not think your specification of results is consistent. On one hand, your output table has two records for the Volvo, but in the final sum-up you apparently only count the "Nok" record (otherwise, there should be 3 types that are "also Unknown").
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.