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

Hi,

i have a data set with 4 variable, data set is shown below:

Storeid ProdId Date SP

1 101 22/1/2013 18

1 101 23/1/2013 18

1 101 24/1/2013 19

1 101 25/1/2013 18

1 101 26/1/2013 19

1 101 27/1/2013 19

Require output is:

Storeid ProdId Date SP

1 101 22/1/2013 18

1 101 24/1/2013 19

1 101 25/1/2013 18

1 101 26/1/2013 19


How to retrieve particular record when price is increasing or decresing?


1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

data want;

   set have;

   by date notsorted;

   if sp=lag(sp) then delete;

run;

View solution in original post

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

Here is a solution, one comment though.  Before checking your solution I wrote _N_ > 1 before first.date, didn't think you would want the first record.

data have;

infile cards;

informat date ddmmyy10.;

format date mmddyy10.;

input Storeid$ ProdId$ Date SP;

cards;

1 101 22/1/2013 18

1 101 23/1/2013 18

1 101 24/1/2013 19

1 101 25/1/2013 18

1 101 26/1/2013 19

1 101 27/1/2013 19

;

run;

data want;

set have;

_l_sp = lag(sp);

by date notsorted;

if first.date and _l_sp > sp then _increase = 1;

if first.date and _l_sp < sp then _decrease = 1;

if _increase = 1 or _decrease = 1 then output;

drop _:;

run;

slchen
Lapis Lazuli | Level 10

data want;

   set have;

   by date notsorted;

   if sp=lag(sp) then delete;

run;

Astounding
PROC Star

Another opinion:

data want;

   set have;

   by StoreID ProdID SP notsorted;

   if first.sp;

run;

Edited a couple of times, but this should do the trick.  Good luck.

Astounding
PROC Star

And so what would the right outcome be for this data?  And what do your solutions actually generate?

Storeid ProdId Date SP

1 101 22/1/2013 18

1 101 23/1/2013 18

1 101 24/1/2013 19

1 101 25/1/2013 18

1 101 26/1/2013 19

1 101 27/1/2013 19

1 102 22/1/2013 19

1 102 23/1/2013 20

1 102 24/1/2013 20

1 102 25/1/2013 21

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1417 views
  • 5 likes
  • 4 in conversation