Hi all!
below is my code. So the code with the if statement works totally fine. I was trying to do the same thing using a select statement, but I got 0 observations except for ShipDays<3. Does anyone know what's wrong?
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
if ShipDays<3 then output work.fast;
else if ShipDays>7 then output work.veryslow;
else if ShipDays>5 and ShipDays<7 then output work.slow;
drop Employee_ID;
run;
/*problem1 part b*/
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
select(ShipDays);
when (ShipDays<3) output work.fast;
when (ShipDays>7) output work.veryslow;
when ((ShipDays>5)and(ShipDays<7)) output work.slow;
otherwise;
end;
drop Employee_ID;
run;
Select should not have the SHIPDAYS in the first SELECT statement.
I believe you're running into the issue illustrated in Example 4.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p09213s9jc2t99n1vx0omk2rh9ps.htm
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
select;
when (ShipDays<3) output work.fast;
when (ShipDays>7) output work.veryslow;
when ((ShipDays>5)and(ShipDays<7)) output work.slow;
otherwise;
end;
drop Employee_ID;
run;
FYI - please include the log in your future questions.
@wxie22 wrote:
Hi all!
below is my code. So the code with the if statement works totally fine. I was trying to do the same thing using a select statement, but I got 0 observations except for ShipDays<3. Does anyone know what's wrong?
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
if ShipDays<3 then output work.fast;
else if ShipDays>7 then output work.veryslow;
else if ShipDays>5 and ShipDays<7 then output work.slow;drop Employee_ID;
run;
/*problem1 part b*/
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
select(ShipDays);
when (ShipDays<3) output work.fast;
when (ShipDays>7) output work.veryslow;
when ((ShipDays>5)and(ShipDays<7)) output work.slow;
otherwise;
end;
drop Employee_ID;run;
Select should not have the SHIPDAYS in the first SELECT statement.
I believe you're running into the issue illustrated in Example 4.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p09213s9jc2t99n1vx0omk2rh9ps.htm
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
select;
when (ShipDays<3) output work.fast;
when (ShipDays>7) output work.veryslow;
when ((ShipDays>5)and(ShipDays<7)) output work.slow;
otherwise;
end;
drop Employee_ID;
run;
FYI - please include the log in your future questions.
@wxie22 wrote:
Hi all!
below is my code. So the code with the if statement works totally fine. I was trying to do the same thing using a select statement, but I got 0 observations except for ShipDays<3. Does anyone know what's wrong?
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
if ShipDays<3 then output work.fast;
else if ShipDays>7 then output work.veryslow;
else if ShipDays>5 and ShipDays<7 then output work.slow;drop Employee_ID;
run;
/*problem1 part b*/
data work.fast work.slow work.veryslow;
set hw2.allorders;
where Order_Type=2 or Order_Type=3;
ShipDays=Delivery_Date-Order_Date;
select(ShipDays);
when (ShipDays<3) output work.fast;
when (ShipDays>7) output work.veryslow;
when ((ShipDays>5)and(ShipDays<7)) output work.slow;
otherwise;
end;
drop Employee_ID;run;
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.