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;


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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