data _NULL_;
call symput('c_dt',input(&currdate_sql,yymmdd10.));
call symput ( 'qtr_start_1', put(intnx('quarter',&c_dt,-1,'b'),date9.));
call symput ( 'qtr_end_1', put(intnx('quarter',&c_dt,-1,'e'),date9.));
call symput ( 'qtr_start_2', put(intnx('quarter',&c_dt,-2,'b'),date9.));
call symput ( 'qtr_end_2', put(intnx('quarter',&c_dt,-2,'e'),date9.));
call symput ( 'qtr_start_3', put(intnx('quarter',&c_dt,-3,'b'),date9.));
call symput ( 'qtr_end_3', put(intnx('quarter',&c_dt,-3,'e'),date9.));
call symput ( 'qtr_start_4', put(intnx('quarter',&c_dt,-4,'b'),date9.));
call symput ( 'qtr_end_4', put(intnx('quarter',&c_dt,-4,'e'),date9.));
run;
data quarters;
set group12;
if datepart(report_dt_p) GE intnx('month', "&trend_end."d /*&trend_end.*/, -2) then Q1_count=count;
else Q1_count=0;
if datepart(report_dt_p) GE intnx('month', "&trend_end."d /*&trend_end.*/, -5) and datepart(report_dt_p)
LT intnx('month',"&trend_end."d /*&trend_end.*/, -2) then Q2_count=count; else Q2_count=0;
if datepart(report_dt_p) GE intnx('month', "&trend_end."d /*&trend_end.*/, -8) and datepart(report_dt_p)
LT intnx('month', "&trend_end."d /*&trend_end.*/, -5) then Q3_count=count;else Q3_count=0;
if datepart(report_dt_p) LT intnx('month', "&trend_end."d /*&trend_end.*/, -8) then Q4_count=count;
else Q4_count=0;
if quarter='Q1' then Q1_count=count; else Q1_count=0;
if quarter='Q2' then Q2_count=count; else Q2_count=0;
if quarter='Q3' then Q3_count=count; else Q3_count=0;
if quarter='Q4' then Q4_count=count; else Q4_count=0;
run;
sample data
Q1_count |
Q2_count |
Q3_count |
Q4_count |
0 |
1 |
2 |
1 |
6 |
19 |
9 |
81 |
3 |
5 |
0 |
1 |
10 |
9 |
0 |
0 |
1 |
6 |
5 |
2 |
Here is my question. Is there a way to assign the various Q counts a header based on the quarter. For example Q1_Count becomes Q1_Count_”&qtr_start_1” ||&qtr_end_1” or Q1_count_1jul2015-30Sep2015
Do you understand what the program is doing? In particular, do you understand SAS dates, INTNX, and CALL SYMPUT? If so, it should be easy enough. (If not, you have some studying to do.) Add a few more date computations and CALL SYMPUTs to the top DATA step. They will create macro variables holding the labels you want, and you can assign them as variable labels in the bottom DATA step using a LABEL statement.
I wouldn't recommend changing the variable names, just assign labels instead. It is extremely cumbersome to deal with variable names that contain nonstandard characters such as a dash. Make sure you instruct the reporting procedure that you use that it should use the labels instead of the variable names as column headings.
Good luck.
I have a sneaking suspicion that much of that code isn't needed at all and an appropriate custome picture format with date directives might work just as well. And with counts as the objective possibly using the format on a date variable from your raw data in a report procedure.
I haven't dived into your logic, but it's rarely wise to create measurement columns based on the time dimension.
Instead, create rows for each quarter, and leave the transposing to any succeeding reporting procedure.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.