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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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