BookmarkSubscribeRSS Feed
Franck1048
Fluorite | Level 6

I'm producing these two tables with proc report:

 

report1.png

Using this code :

 

 

proc report data=d_result.f_medo_tbc;

	title 	"Soldes courants - &DemogAnneeCourante";
	column	tx_couv_cour_arrond 
		Solde1_1GRegie_Cour,(n pctn)
		Solde1_1GRegie_Cour=cour_sum
		;

	define tx_couv_cour_arrond / group format=taux_de_couverture.;
	define pctn / FORMAT=NLPCTN8.1;
	define cour_sum / analysis sum f=6.0;


run;

proc report data=d_result.f_medo_tbc;

	title 	"Soldes courants - &DemogAnneeProjetee";
	column	tx_couv_proj_arrond
		Solde1_2GRegie_2021,(n pctn)
		Solde1_2GRegie_2021=proj_sum
		;

	define tx_couv_proj_arrond / group format=taux_de_couverture.;
	define pctn / FORMAT=NLPCTN8.1;
	define proj_sum / analysis sum f=6.0;

run;

 

 

 

 

 

I want to get this result (doctored image) :

 

report2.png

 

As you can see, the format used for grouping is the same (taux_de_couverture.), but the variables differ.

 

 

 

 

I tried combining the two procs into a single one...

 

proc report data=d_result.f_medo_tbc;

	title 	"Soldes courants - &DemogAnneeCourante";
	column	tx_couv_cour_arrond 
			Solde1_1GRegie_Cour,(n pctn)
			Solde1_1GRegie_Cour=cour_sum

			tx_couv_proj_arrond
			Solde1_2GRegie_2021,(n pctn)
			Solde1_2GRegie_2021=proj_sum
			;

	define tx_couv_cour_arrond / group format=taux_de_couverture.;
	define pctn / FORMAT=NLPCTN8.1;
	define cour_sum / analysis sum f=6.0;

	define tx_couv_proj_arrond / group format=taux_de_couverture.;
	define pctn / FORMAT=NLPCTN8.1;
	define proj_sum / analysis sum f=6.0;


run;

 

..but as expected the grouping simply gets divided into further groups :

 

report3.png

 

 

I tried a solution using proc tabulate but I'm also stuck with two procs.

 

Any ideas? Thank you!

5 REPLIES 5
pink_poodle
Barite | Level 11

When you consolidate the tables like this, you are adding an across variable, that has two values: "Solde...2021" and "Solde...Cour." This variable should appear in the code:

 

define newvar/ across;

 

To add this variable, you would need to flag your data with either "Solde...2021" or "Sold...Cour", since this variable is basically a flag.

The following SAS example has a table similar to yours, the part about formats is less relevant:

 

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p0be7xxo5rliwfn1ie99h...

Franck1048
Fluorite | Level 6

I'm not sure this is what I'm trying to do. It looks like it, but after reading it's not the same.

 

Across splits a single variable into columns.

 

For my needs, it's my grouping variables that are different. 

 

tx_couv_cour_arrond and tx_couv_proj_arrond are two different variables that I make groups with using a common format.

 

So one observation could be in group 01 for tx_couv_cour_arrond and in group 04 for tx_couv_proj_arrond.

pink_poodle
Barite | Level 11

I see the variables that have names starting with 'tx.' I agree with you, but I am writing about the other two variables that are your group labels, starting with 'Solde1.' These group labels can definitely be in a variable Group having flag values 1 ('Solde1_1GRegie_Cour') or 2 ('Solde1_2GRegie_2021'). Then you can make that Group variable an across variable, producing the table that you show.

Franck1048
Fluorite | Level 6

Ok I understand. Then yes across is definitely part of the solution.

 

I've still yet to figure out if it's possible to output a single table using two different vars with the same format for grouping.

pink_poodle
Barite | Level 11

 Where is the variable tx_couv_proj_arrond on the doctored image?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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