BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,
Plz find the solution for this problem.
I have demand dataset of parts at different plants from April 2001 to March 2008 as follows:

Plant Date Part Demand

1000 apr2001 ax1 23
2000 apr2001 ax1 34
1000 apr2001 ax2 43
2000 apr2001 ax2 53

1000 may2001 ax1 32
2000 may2001 ax1 54
1000 may2001 ax3 87

1000 June 2001 ax3 12
1000 June 2001 ax4 11
2000 June 2001 ax1 32

Now I want to subset dataset as:
1. Parts with first demand in apr2001 at each plant (Dataset from April 2001 to march 2008)
2. Parts with first demand in may 2001 at each plant (Dataset from May 2001 to March 2008) with exclusion of parts started in April 2001.
3. Parts with first demand in June 2001 at each plant with exclusion of parts started in April 2001 and May 2001.

I mean I want to subset my data set as;
1. Whole data set (April 2001 to March2008) of parts (ax1 and ax2) which started in April2001 with each plant.
2. Whole data set (May 2001 to March 2008) of part (ax3) stated in May 2001 with each plant but not already present in April 2001 (not of ax1 and ax2).
3. Same For June 2001(ax4)


My approach is this way:


data want;
set test;
by part;
if first.part and put(date,monyy7.)='APR2001';
run;


The above code gives me only those parts that are ordered for first time.

O/p for above code is :
Plant Date part Demand
1000 APR2001 ax1 23
1000 APR2001 ax2 43

But this is not what I am interested because ax1 and ax2 part is also ordered for first time
on plant 2000,so my o/p should be this way:
Plant Date part Demand
1000 APR2001 ax1 23
1000 APR2001 ax1 34
2000 APR2001 ax1 34
2000 APR2001 ax2 53

If I just use apr2001 in if stmt I can get all values but still there will be duplicate values which will be added.


If I run the same query for month of may2001 with this code:

data want;
set test;
by part;
if first.part and put(date,monyy7.)='MAY2001';
run;

My o/p is this way:
Plant Date part Demand
1000 MAY2001 ax3 87
1000 MAY2001 ax5 87

But this is not again correct because part ax5 . is also placed for order for first time even on plant 5000 ,so that record should also be added in my o/p:

My o/p is this way:
Plant Date part Demand
1000 MAY2001 ax3 87
1000 MAY2001 ax5 87
5000 MAY2001 ax5 87




thanks

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 563 views
  • 0 likes
  • 1 in conversation