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

Hello,

 

I have the following data table:

 

IDMeasureNumberDateFlagOutput
1A511/1/201413
1A112/1/201413
1A31/1/201513
1A510/1/201515
1A611/1/201515
1A812/1/201515
1A31/1/201615
1A62/1/201615
1A18/1/201716
1A69/1/201716
1A1010/1/201716
1A211/1/201716
1A1412/1/201716
1A51/1/201816

 

I am trying to select the output variable with the greater output number, but earlier time period.  For example, the output '5' is greater than '3', but the date is earlier than the output '6', so I would select that.  However, I'm not sure how to write this coding.  Eventually, I want to be able to select the following data only from the above table.

 

IDMeasureNumberDateFlagOutput
1A510/1/201515
1A611/1/201515
1A812/1/201515
1A31/1/201615
1A62/1/201615

 

Thank you for any help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The only way I can interpret your request is: "Find the OUTPUT group which is not the smallest OUTPUT number and not the latest mean (or min, or max, etc) date." A solution would then be:

 


proc sql;
select id, measure, number, date, flag, output
from (select *, mean(date) as meanDate from have group by id, measure, output)
group by id, measure
having output > min(output) and meanDate < max(meanDate);
quit;

 

PG

View solution in original post

2 REPLIES 2
ballardw
Super User

What role does the variable named NUMBER play in this process?

 

Why are none of the OUTPUT values of 6 selected? You seem to have an unstated rule other than larger value of output and date sequence.

 

I can get you desired data from that example with

 

data want;

   set have;

   where output=5;

run;

 

but that isn't exercising any rules. Perhaps you could provide example start and end data sets where the OUTPUT variable is a different value. Best is to provide examples as data step so we can be sure we are using data similar to yours. Paste it into a code box opened with the forum's {I} such as:

data have;
input ID Measure $ Number Date :mmddyy10. Flag Output;
format date mmddyy10.;
datalines;
1 A 5 11/1/2014 1 3 
1 A 1 12/1/2014 1 3 
1 A 3 1/1/2015 1 3 
1 A 5 10/1/2015 1 5 
1 A 6 11/1/2015 1 5 
1 A 8 12/1/2015 1 5 
1 A 3 1/1/2016 1 5 
1 A 6 2/1/2016 1 5 
1 A 1 8/1/2017 1 6 
1 A 6 9/1/2017 1 6 
1 A 10 10/1/2017 1 6 
1 A 2 11/1/2017 1 6 
1 A 14 12/1/2017 1 6 
1 A 5 1/1/2018 1 6 
run;

By the way I am guessing that the first number in the date is the month.

 

PGStats
Opal | Level 21

The only way I can interpret your request is: "Find the OUTPUT group which is not the smallest OUTPUT number and not the latest mean (or min, or max, etc) date." A solution would then be:

 


proc sql;
select id, measure, number, date, flag, output
from (select *, mean(date) as meanDate from have group by id, measure, output)
group by id, measure
having output > min(output) and meanDate < max(meanDate);
quit;

 

PG

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1005 views
  • 0 likes
  • 3 in conversation