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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1760 views
  • 0 likes
  • 4 in conversation