BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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

4 REPLIES 4
Reeza
Super User
Deal with your data in a vertical (long) format and then transpose it, using ID and IDLABEL to automatically create your variable name/headers.
Astounding
PROC Star

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.

ballardw
Super User

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.

LinusH
Tourmaline | Level 20

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.

Data never sleeps

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1672 views
  • 2 likes
  • 5 in conversation