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

I have a pdf report like below:

 

.......

column CPN VINT State Var1 Var2

define CPN / order;

define VINT / order descending;

define State / order;

define Var1 /sum;

define Var2 /sum;

........

 

In the final report,

CPN only show up once for each CPN group (CPN1 X All VINT X All State).

I want CPN show up every time for each VINT not once.

 

How can I do it?

 

Thanks.

 

Jian

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi Jian,

 

Here is an example (tested only with listing output, though):

data test;
input CPN VINT State $ Var1 Var2;
cards;
1 5 FL 1 11
1 8 DE 2 22
1 8 AK 3 33
1 5 MI 4 44
2 7 TX 5 55
2 4 NC 6 66
2 7 GA 7 77
;

/* Before */

proc report data=test nowd;
column CPN VINT State Var1 Var2;
define CPN / order;
define VINT / order descending;
define State / order;
define Var1 / sum;
define Var2 / sum;
run;

/* After */

proc report data=test nowd;
column CPN CPN_ VINT State Var1 Var2;
define CPN / order noprint;
define CPN_ / computed '      CPN';
define VINT / order descending;
define State / order;
define Var1 / sum;
define Var2 / sum;
compute before CPN;
  temp=CPN;   /* Temporary variable TEMP is assigned the */
endcomp;      /* value of CPN when it is available.      */
compute before VINT;
  temp2=VINT; /* Temporary variable TEMP2 is assigned the */
endcomp;      /* value of VINT when it is available.      */
compute CPN_ / character length=9;
  if temp2 ne lag(temp2) then CPN_=put(temp,9.);
endcomp;
run;

This is partially based on Carpenter's Complete Guide to the SAS® REPORT Procedure, p. 185 f., where they repeat the value on each row. I introduced the LAG function to restrict the repetitions to the first observation of each VINT group. Maybe there is a more elegant way to accomplish this.

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hi Jian,

 

Here is an example (tested only with listing output, though):

data test;
input CPN VINT State $ Var1 Var2;
cards;
1 5 FL 1 11
1 8 DE 2 22
1 8 AK 3 33
1 5 MI 4 44
2 7 TX 5 55
2 4 NC 6 66
2 7 GA 7 77
;

/* Before */

proc report data=test nowd;
column CPN VINT State Var1 Var2;
define CPN / order;
define VINT / order descending;
define State / order;
define Var1 / sum;
define Var2 / sum;
run;

/* After */

proc report data=test nowd;
column CPN CPN_ VINT State Var1 Var2;
define CPN / order noprint;
define CPN_ / computed '      CPN';
define VINT / order descending;
define State / order;
define Var1 / sum;
define Var2 / sum;
compute before CPN;
  temp=CPN;   /* Temporary variable TEMP is assigned the */
endcomp;      /* value of CPN when it is available.      */
compute before VINT;
  temp2=VINT; /* Temporary variable TEMP2 is assigned the */
endcomp;      /* value of VINT when it is available.      */
compute CPN_ / character length=9;
  if temp2 ne lag(temp2) then CPN_=put(temp,9.);
endcomp;
run;

This is partially based on Carpenter's Complete Guide to the SAS® REPORT Procedure, p. 185 f., where they repeat the value on each row. I introduced the LAG function to restrict the repetitions to the first observation of each VINT group. Maybe there is a more elegant way to accomplish this.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 937 views
  • 1 like
  • 2 in conversation