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

Dear altruists,
I am a new SAS user.
I have the following dataset (I have attached the SAS dataset in the end):

Company_IDDateFiscal_Quarter
12102009-03-314
12102009-06-301
12102009-09-302
10942009-03-313
10942009-06-304
10942009-09-301
13272009-03-312
13272009-06-303
13272009-09-304
10452009-03-311
10452009-06-302
10452009-09-303
11202009-03-164
11202009-06-301
11202009-09-302

 

I want to create two output datasets on the following condition:
During the period from 15 March 2009 to 14 March 2010, if the first observation of a certain Company_ID has a Fiscal_Quarter value of 4, then this observation should be put in a new dataset.
All the remaining observations will be sent to another dataset.


So, the first output dataset would be as follows:

Company_IDDateFiscal_Quarter
12102009-03-314
11202009-03-164

 

And the second output dataset would be as follows:

Company_IDDateFiscal_Quarter
12102009-06-301
12102009-09-302
10942009-03-313
10942009-06-304
10942009-09-301
13272009-03-312
13272009-06-303
13272009-09-304
10452009-03-311
10452009-06-302
10452009-09-303
11202009-06-301
11202009-09-302


Thank you in advance for all your support!

1 ACCEPTED SOLUTION
4 REPLIES 4
PaigeMiller
Diamond | Level 26
data first_output_data_set second_output_data_set;
    set have;
    by company_id notsorted;
    if first.company_id=4 then output first_output_data_set;
    else output second_output_data_set;
run;

This code is UNTESTED. If you want tested code, please provide (a portion of) the data as SAS data step code (instructions).

--
Paige Miller
mmh
Obsidian | Level 7 mmh
Obsidian | Level 7

Thank you so much for your reply.
Unfortunately, it is not working.
I am adding the datastep here for you:

data have;
input Company_ID $4. Date Fiscal_Quarter;
informat Date date9.;
format Date date9.;
cards;
1210 31mar2009 4
1210 30jun2009 1
1210 30sep2009 2
1094 31mar2009 3
1094 30jun2009 4
1094 30sep2009 1
1327 31mar2009 2
1327 30jun2009 3
1327 30sep2009 4
1045 31mar2009 1
1045 30jun2009 2
1045 30sep2009 3
1120 16mar2009 4
1120 30jun2009 1
1120 30sep2009 2
;
run;

mmh
Obsidian | Level 7 mmh
Obsidian | Level 7
Thank you so much Kurt!
I really appreciate your kind support!

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
  • 4 replies
  • 430 views
  • 1 like
  • 3 in conversation