BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wxie22
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;


 

View solution in original post

1 REPLY 1
Reeza
Super User

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;


 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 735 views
  • 1 like
  • 2 in conversation