BookmarkSubscribeRSS Feed
Pandu2
Obsidian | Level 7
Hi All,
I require some assistance from you all.
I've a table has 10 columns but I require output table based on 2 columns only they are sas_date and amount . And it has data of February to till date. In that I need to keep a condition like if the amount is max for a record then I need the overall rows where the sas_date should be older date.
Ex:
Sas_date x y z amount
09feb2022 1 2 3 1
01feb2022 1 2 3 5
20mar2022 1 2 3 2
11apr2022 6 6 7 8
24feb2022 6 6 7 9
25mar2022 6 6 7 9
17apr2022 9 8 6 1
19mar2022 9 8. 6. 1

Output table should be:
Sas_date. | X. Y. Z. Amount
01feb2022| 1 2. 3. 5
24feb 2022 6. 6. 7. 9
19mar2022 9. 8. 6 1
If the amount has all 1's for every row then the amount should be same but the sas date should be an older date.

Thanks.
16 REPLIES 16
PaigeMiller
Diamond | Level 26

In that I need to keep a condition like if the amount is max for a record then I need the overall rows where the sas_date should be older date.

 

I'm not understanding this. Please explain in more detail and walk us through an example step by step.

--
Paige Miller
Pandu2
Obsidian | Level 7
Hi, thanks for responding.
Could you please look at the example which I added
PaigeMiller
Diamond | Level 26

@Pandu2 wrote:
Hi, thanks for responding.
Could you please look at the example which I added

As far as I can see, you have not explained anything (which I specifically asked for), nor have you walked us through the example step-by-step (which I specifically asked for). So I still don't understand.

--
Paige Miller
Pandu2
Obsidian | Level 7
data have;

input id term project sasdate date1

cards;

1 10 197 01may2022 07feb2022

1 10 197 09apr2022
12mar2022

1 10 197 30apr2022
15apr2022

1 10 201 31mar2022
29mar2022

1 10 201 17feb2022
11jan2022

;
This is the data I've and what I require is sas_date should be greater than date1 and the sas_date should be the earliest date. Once the condition meets that row should be picked by grouping id term project.
Output table should be like :

1 10 197 09apr2022
12mar2022


1 10 201 17feb2022
11jan2022

;
I hope you got me.
Kurt_Bremser
Super User

Please review your code so that the step works without ERRORs or WARNINGs, then re-post it by copy/pasting the code into a code box opened with the "little running man" icon.

If you have trouble writing a simple data step, we should tackle this first before you dig deeper into SAS coding, so don't hesitate to ask how to write the step so that it works.

Pandu2
Obsidian | Level 7
Please ignore the errors which I wrote in data step, but please do understand the requirements. Thankyou.
Pandu2
Obsidian | Level 7
Atleast, please do let me know how to find the earliest date in a bunch of date values. Thankyou.
Pandu2
Obsidian | Level 7
Can we find the earliest date by using min function with a date9 format . Please provide an example for it. Thankyou.
Pandu2
Obsidian | Level 7
I've a date variable which is in date9 format.
Kurt_Bremser
Super User
You only have one date1 value in your data. Is this valid for the whole id, for id and term, or id, term and project? If the latter, which value is to be used for the second project?
Pandu2
Obsidian | Level 7
I've two date variables
1. Sasdate
2.date1
And both these two are valid for whole Id,term, project variables.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 16 replies
  • 1094 views
  • 0 likes
  • 3 in conversation