BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

Hello,

 

by launching this proc report, the column AXE_PRODUIT is repeated as intended but it does not work for column generation and I don't know why. thanks a lot in advance for your help.

regard,Capture.PNG

Nasser

 PROC REPORT DATA = work.T7_MEASURES_M0 (where=(INDEX(Measure,'sans cumul'))) nowd ;

column AXE_PRODUIT GENERATION measure periode_month_M0 , value ;

define AXE_PRODUIT / group 'Produit' ;

COMPUTE AXE_PRODUIT ;

 IF AXE_PRODUIT NE '' then hold_axe_produit = AXE_PRODUIT ;

 IF AXE_PRODUIT EQ '' then AXE_PRODUIT = hold_axe_produit ;

ENDCOMP ;

define GENERATION / group 'Génération' ; 

COMPUTE GENERATION ;

 IF GENERATION NE '' then hold_GENERATION = GENERATION ;

 IF GENERATION EQ '' then GENERATION = hold_GENERATION ;

ENDCOMP ;

define measure / group 'Indicateur' ;

define periode_month_M0 / across '' ;

define value / '' ;

compute value ;

 if INDEX(measure,'Mont') then do ;

 call define(_COL_,'FORMAT','12.2') ;

end;

else call define(_COL_,'FORMAT','percent12.9') ;

endcomp ;

RUN ;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  You did not post any test data, so it is hard to comment in great detail. However, the code you're using looks like it was modeled on the automatic PROC REPORT code that is generated by Enterprise Guide. Although the automatic code uses OK techniques for most cases, in some instances, the code they generate needs to be modified. Example #1 in the screen shot below uses SASHELP.PRDSALE data to mimic the basics of your report and as you can see, the second column is not populated as you want. However, in Example #2, using an alternate technique (COMPUTE BEFORE), you can ALWAYS grab a group or order value at the break BEFORE the group and this is the most reliable way to create a temporary variable to hold the value of a group or order variable for use in a subsequent COMPUTE block.

 

  Then using the COMPUTED usage technique along with NOPRINT, you can NOPRINT the actual variables from the data and make "display" versions of the variables to appear on each row. Here's the difference in the 2 techniques:

use_diff_technique_correct.png

 

and here's the code that generated the above reports:

proc sort data=sashelp.prdsale out=prdsale;
by product year;
where quarter=1 and year=1993 and product in ('SOFA' 'CHAIR');
run;
  
PROC REPORT DATA = prdsale nowd ;
  title '1) code as posted -- problem with year column';
	column product year country actual,month ;
	define product / group 'Produit' ;
		COMPUTE product ;
		IF product NE '' then hold_product = product ;
		IF product EQ '' then product = hold_product ;
		ENDCOMP ;
	define year / group 'Génération' ; 
		COMPUTE year ;
		IF year NE . then hold_year = year ;
		IF year EQ . then year = hold_year ;
		ENDCOMP ;
	define country / group 'Indicateur';
	define month / across '' f=monname. order=internal;
	define actual / '' ;
RUN ;
  
PROC REPORT DATA = prdsale nowd ;
  title '2) Revised code using different technique';
	column product year disp_prod disp_year country actual,month ;
	define product / group 'Produit' noprint;
	define year / group 'Génération' noprint; 
	define disp_prod / computed 'Produit';
	define disp_year / computed 'Génération';
	define country / group 'Indicateur';
	define month / across '' f=monname. order=internal;
	define actual / '' ;
    compute before product;
	   hold_prod=product;
	endcomp;
	compute before year;
	   hold_year = year;
	endcomp;
	COMPUTE disp_prod / character length=20;
		disp_prod=hold_prod;
	ENDCOMP ;
	COMPUTE disp_year ;
		disp_year = hold_year;
	ENDCOMP ;

RUN ;

Hope this helps,

 

cynthia

View solution in original post

5 REPLIES 5
Nasser_DRMCP
Lapis Lazuli | Level 10
PROC REPORT DATA = work.T7_MEASURES_M0 (where=(INDEX(Measure,'sans cumul'))) nowd ;
	column AXE_PRODUIT GENERATION measure periode_month_M0  , value ;
	define AXE_PRODUIT / group 'Produit' ;
		COMPUTE AXE_PRODUIT ;
		IF AXE_PRODUIT NE '' then hold_axe_produit = AXE_PRODUIT ;
		IF AXE_PRODUIT EQ '' then AXE_PRODUIT = hold_axe_produit ;
		ENDCOMP ;
	define GENERATION / group 'Génération' ; 
		COMPUTE GENERATION ;
		IF GENERATION NE '' then hold_GENERATION = GENERATION ;
		IF GENERATION EQ '' then GENERATION = hold_GENERATION ;
		ENDCOMP ;
	define measure /  group 'Indicateur' ;
	define periode_month_M0 / across '' ;
	define value / '' ;
		compute value ;
 		if INDEX(measure,'Mont') then do ;
 		call define(_COL_,'FORMAT','12.2') ;
 		end;
 		else call define(_COL_,'FORMAT','percent12.9') ;
 		endcomp ;
  	RUN ;

Capture.PNG

 

 

Hello,

 

by executing this proc report, the group "produit" is repeated for all lines as intended. but it does not work for the column "generation"

I don't understand why. thanks a lot in advance for your help

regards,

Nasser

Reeza
Super User
Please don't post the same question multiple times. Note that I've also moved this to the ODS and Base Reporting section as it's more appropriate there and the relevant users will see the question. The forum appears to be having technical issues, so it may take a while for you to get an answer to this. In general, it also helps if you either include sample data so we can run/test your code or use a SASHELP data set.
Nasser_DRMCP
Lapis Lazuli | Level 10

Hello Reeza,

 

sorry for that. thanks for your action.

Cynthia_sas
SAS Super FREQ

Hi:

  You did not post any test data, so it is hard to comment in great detail. However, the code you're using looks like it was modeled on the automatic PROC REPORT code that is generated by Enterprise Guide. Although the automatic code uses OK techniques for most cases, in some instances, the code they generate needs to be modified. Example #1 in the screen shot below uses SASHELP.PRDSALE data to mimic the basics of your report and as you can see, the second column is not populated as you want. However, in Example #2, using an alternate technique (COMPUTE BEFORE), you can ALWAYS grab a group or order value at the break BEFORE the group and this is the most reliable way to create a temporary variable to hold the value of a group or order variable for use in a subsequent COMPUTE block.

 

  Then using the COMPUTED usage technique along with NOPRINT, you can NOPRINT the actual variables from the data and make "display" versions of the variables to appear on each row. Here's the difference in the 2 techniques:

use_diff_technique_correct.png

 

and here's the code that generated the above reports:

proc sort data=sashelp.prdsale out=prdsale;
by product year;
where quarter=1 and year=1993 and product in ('SOFA' 'CHAIR');
run;
  
PROC REPORT DATA = prdsale nowd ;
  title '1) code as posted -- problem with year column';
	column product year country actual,month ;
	define product / group 'Produit' ;
		COMPUTE product ;
		IF product NE '' then hold_product = product ;
		IF product EQ '' then product = hold_product ;
		ENDCOMP ;
	define year / group 'Génération' ; 
		COMPUTE year ;
		IF year NE . then hold_year = year ;
		IF year EQ . then year = hold_year ;
		ENDCOMP ;
	define country / group 'Indicateur';
	define month / across '' f=monname. order=internal;
	define actual / '' ;
RUN ;
  
PROC REPORT DATA = prdsale nowd ;
  title '2) Revised code using different technique';
	column product year disp_prod disp_year country actual,month ;
	define product / group 'Produit' noprint;
	define year / group 'Génération' noprint; 
	define disp_prod / computed 'Produit';
	define disp_year / computed 'Génération';
	define country / group 'Indicateur';
	define month / across '' f=monname. order=internal;
	define actual / '' ;
    compute before product;
	   hold_prod=product;
	endcomp;
	compute before year;
	   hold_year = year;
	endcomp;
	COMPUTE disp_prod / character length=20;
		disp_prod=hold_prod;
	ENDCOMP ;
	COMPUTE disp_year ;
		disp_year = hold_year;
	ENDCOMP ;

RUN ;

Hope this helps,

 

cynthia

Nasser_DRMCP
Lapis Lazuli | Level 10

Hi Cynthia,

 

yes This realy helped me ! thanks a lot

have a good day

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!

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
  • 5 replies
  • 7743 views
  • 0 likes
  • 3 in conversation