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,

	proc transpose data= BEH_AGG_5 out= BEH_AGG_5_CRDGEN_TRSPS (drop = _name_) ;
	by RAC &v_AXE. GENERATION PRODUCTION ;
	var CRD_GEN_MENS_MEAN ;
	id ANNEE_AMO ;
	idlabel ANNEE_AMO_LABEL ;
	run ;

ODS TAGSETS.EXCELXP FILE = "&xlsfile."  style=normal  ;

	ODS TAGSETS.EXCELXP options ( skip_space='1,0,0,0,0' sheet_name='Encours CRD GEN' ) ;
	PROC REPORT DATA = work.BEH_AGG_5_CRDGEN_TRSPS NOwd  ;
	title ;
	format _numeric_ z12.5 ;
  	RUN ;

ODS TAGSETS.EXCELXP CLOSE ;

by launching this code in sas EG environment , it works as intended, year are sorted ascending , 2015, 2016, 2017 (within the excel file) but in bacth mode, years are sorted descending . how can I sort It ?

thanks a lot in advance

Nasser

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I think that you may be going to extra work. You don't provide example starting data but perhaps if you did we might suggest instead of transposing the data at all that you use the BEH_AGG_5 data set and the variable ANNEE_AMO as an Across variable.

 

The report procedure has a LOT of flexibility for arranging and calculating values, and Proc Tabulate a different set of features.

Since the whole purpose of your transpose is apparently to but the year value across the top of report use the tool in Report that will do so.

View solution in original post

6 REPLIES 6
Reeza
Super User

In PROC REPORT you can set the order to Descending/Ascending in the DEFINE statement. Ascending should be the default but you haven't specified it as an order variable either. 

 

I think explicitly setting should remove that issue.

 

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

Nasser_DRMCP
Lapis Lazuli | Level 10

thanks a lot Reeza but I do not understand because "define" within proc report is usefull to sort data.


my need is to sort columns. 2015, 2016 and 2017 are columns names.
before, It was values of "year" column but I need to transpose to get one column for each year in excel. sorry I my issue was not clearly described.

Reeza
Super User

Ok, based on the new information provided, the answer is you're using PROC REPORT in a way that's not really intended. 

More like a PROC PRINT.


You can control the order of variables by declaring them and using them in DEFINE statements. 

 

Because you haven't specified any order, it's a guessing game and sometimes you lose when SAS guesses.

 

*not the intended usage;
proc report data=sashelp.class nowd;
run;

*intended usage;
proc report data=sashelp.class nowd;
column age sex name weight height;
define age / order group;
define sex / 'Sex' just=c;
define name/'Name';
define weight/'Weight';
define height / 'Height';
run;

 You can specify the order by ordering them in the COLUMN statement.

ballardw
Super User

I think that you may be going to extra work. You don't provide example starting data but perhaps if you did we might suggest instead of transposing the data at all that you use the BEH_AGG_5 data set and the variable ANNEE_AMO as an Across variable.

 

The report procedure has a LOT of flexibility for arranging and calculating values, and Proc Tabulate a different set of features.

Since the whole purpose of your transpose is apparently to but the year value across the top of report use the tool in Report that will do so.

Nasser_DRMCP
Lapis Lazuli | Level 10

Hello,
thanks ballard.
I gaveup the proc "transpose" and I use "across" within proc report.

PROC REPORT DATA = work.BEH_AGG_5 nowd  ;
	column RAC Groupe GENERATION production ANNEE_AMO CRD_GEN_MENS_MEAN  ;
	define RAC / group ;
	define Groupe / group ;
	define GENERATION / group ;
	define production / group ;
	define ANNEE_AMO / across  ;
	define CRD_GEN_MENS_MEAN / mean noprint ;
	title ;
  	RUN ;

 

years are correctly transposed and sorted but values of the indicator CRD_GEN_MENS_MEAN are always "1" ???

Nasser_DRMCP
Lapis Lazuli | Level 10

It works !

column RAC Groupe GENERATION production ANNEE_AMO , CRD_GEN_MENS_MEAN

the comma was missing

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