Join Now

Det Gode SAS-program #22A: Benyt ELSE statement

by SAS Employee GeorgMorsing ‎02-27-2016 07:25 AM - edited ‎02-29-2016 04:41 AM (339 Views)

 

Reducér din svartid ved at benytte ELSE statement i Data steppet.

 

Læs mere her.

 

Koden til dette eksempel ses nedenfor og er også vedhæftet denne artikel.

 

Georg

 

* --- Test af ELSE statement ----------;

* --- Dan stor tabel til testformål ---;

Data work.orsales_big;

set sashelp.orsales;

do i=1 to 10000;

output;

if product_line='Sports' then

do j=1 to 6;

output;

end;

end;

drop i j;

run;

* --- Eksempel A: Uden ELSE statement ---;

data _null_;

set work.orsales_big;

if product_line=' ' then bonus=0;

if product_line='Indoor' then Bonus=50;

if product_line='Children' then bonus=100;

if product_line='Clothes & Shoes' then bonus=200;

if product_line='Outdoors' then bonus=300;

if product_line='Sports' then bonus=400;

run;

 

* --- Eksempel B: Med ELSE statement og rækkefølge

efter faldende hypighed ---;

data _null_;

set work.orsales_big;

if product_line='Sports' then bonus=400;

else if product_line='Clothes & Shoes' then bonus=200;

else if product_line='Children' then bonus=100;

else if product_line='Outdoors' then bonus=300;

else if product_line=' ' then bonus=0;

else if product_line='Indoor' then Bonus=50;

run;

Attachment