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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.