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

Hi All,

 

I need to create (or change) the 'event_dt' variable to match the relevant Australian Financial year quarters by several years;

qtr 1 = Jul - Sep

Qtr 2 = Oct - Dec

Qtr 3 = Jan - Mar

Qtr 4 = Apr - Jun

 

 

I have tried several methods however the results still returns a date value which then doesn't allow me to Summarize by the quarter/year.

 

Hope this makes sense.

 

Regrads

 

Dean

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@DME790 wrote:


 

I have tried several methods however the results still returns a date value which then doesn't allow me to Summarize by the quarter/year.

 

 


Please include what you've tried in the future. 

 

You don't need to make a conversion to summarize by quarter/year, you need to apply the correct format and SAS summarizes using the formatted value. See the PROC FREQ example below which uses the SAS date to do the counts.

 

*Create a sample data set;
data have;
    do i=1 to 12;
        sas_date = mdy(i, 15, 2017);
        output;
    end;
run;

*create the quarter variable as a SAS date or a number;
data want;
    set have;

*since your quarters are 6 months off the standard def, move date back 6 months; quarter_date = intnx('month', sas_date, -6, 's'); quarter_number=qtr(quarter_date); format sas_date date9. quarter_date qtr4.; run; *count # / quarter using SAS date; proc freq data=want order=freq; table quarter_date; run;

View solution in original post

5 REPLIES 5
ChrisBrooks
Ammonite | Level 13

Can you show us what your data looks like by creating a simple data step to import it into SAS along with your desired output?

FredrikE
Rhodochrosite | Level 12

Not really shure what you want, but this might help 🙂

 

data test;

event_dt = '21feb2017:13:52:50'dt;

year = year(datepart(event_dt));

qtr = qtr(datepart(event_dt));

select (qtr);

when (1) qtrA = 3;

when (2) qtrA = 4;

when (3) qtrA = 1;

when (4) qtrA = 2;

otherwise;

end;

run;

Reeza
Super User

@DME790 wrote:


 

I have tried several methods however the results still returns a date value which then doesn't allow me to Summarize by the quarter/year.

 

 


Please include what you've tried in the future. 

 

You don't need to make a conversion to summarize by quarter/year, you need to apply the correct format and SAS summarizes using the formatted value. See the PROC FREQ example below which uses the SAS date to do the counts.

 

*Create a sample data set;
data have;
    do i=1 to 12;
        sas_date = mdy(i, 15, 2017);
        output;
    end;
run;

*create the quarter variable as a SAS date or a number;
data want;
    set have;

*since your quarters are 6 months off the standard def, move date back 6 months; quarter_date = intnx('month', sas_date, -6, 's'); quarter_number=qtr(quarter_date); format sas_date date9. quarter_date qtr4.; run; *count # / quarter using SAS date; proc freq data=want order=freq; table quarter_date; run;
DME790
Pyrite | Level 9
Thanks Reeza - can you let me know what the 'S' does in the quarter_date = intnx('month', sas_date, -6, 's');
Cheers
Dean
Reeza
Super User
The fourth parameter is alignment option. In this case I've used 15 as the date and set it to the same since all months have a 15. Other options are beginning, end, middle. See the docs for more details.

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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