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

Order Type count

14
21
32

 

 

Obs CustomerID OrderDate DeliveryDate OrderType Quantity

8903JAN201104JAN201116
8901OCT201101OCT201111
8901OCT201101OCT201111
8915DEC201115DEC201114
8917JUN201121JUN201122
255004MAY201109MAY201133
255004MAY201109MAY201131

 

These are the two tables (let's call them table1 and table2). I have to combine these two tables

and change it into one where there is only one observation for each ordertype.

It would have to look like (this is only part of it):

Obs OrderDate1 OrderDate2 OrderDate3 OrderDate4 DeliveryDate1123    

03JAN201101OCT201101OCT201104JAN201101OCT2011
17JUN2011. 21JUN2011.
04MAY201104MAY2011 09MAY201109MAY2011
     
     
     
     

 

I don't need help with everything.. I need to use arrays to built this dataset, but I can't seem to get it.

I tried to do the first part of only the orderdate, but obviously that didn't work.

 

Data orderfact;
array order{4} OrderedDate1 OrderedDate2 OrderedDate3 OrderedDate4;
do i = 1 to 7;
set orderfact;
by OrderType;
order{OrderType} = OrderedDate;
end;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

An easy way is to put the DO loop around the SET statement. 

Increment the a counter so you know where in the array to but the date value.

Stop the DO loop when you get to the last value of that order type.

data orderfact;
do row=1 by 1 until (last.ordertype);
  set orderfact;
  by OrderType;
  array Order  OrderedDate1-OrderedDate4;
  order[row] = OrderedDate;
end;
  format OrderedDate: date9.;
run;

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

An easy way is to put the DO loop around the SET statement. 

Increment the a counter so you know where in the array to but the date value.

Stop the DO loop when you get to the last value of that order type.

data orderfact;
do row=1 by 1 until (last.ordertype);
  set orderfact;
  by OrderType;
  array Order  OrderedDate1-OrderedDate4;
  order[row] = OrderedDate;
end;
  format OrderedDate: date9.;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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