BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

In the following program I want to display 4 column with percent format (percent9.1)

pctn

pctsum

Diff_PCT_Y

Diff_PCT_cust

 

 

I want also to ask why  pctn  and pctsum are not in define statements?

Data tbl1806;
input ID  team $ Y ;
cards;
1 817  10
2 817  20
3 818  30
4 828  40
5 818  50
6 890  60
7 890  70
8 890  80
9 890  90
10 890 100
;
Run;

Data tbl1712;
input ID team $  Y;
cards;
1 817  15
2 817  25
3 818  35
4 828  45
5 818  55
6 890  65
7 818  70
11 818 110
12 818 120
;
Run;

data combined;
set tbl1806 tbl1712 indsname=ds;
length mon $ 5;
mon=substr(scan(ds,2,'.'),4);
run;

proc format library=work;
value $type (multilabel notsorted)
'817' = '817'
'818' = '818'
'828' = '828'
'817','818','828' = '817_818_828'
' '='All'
other = 'not 817_818_828'
;
run;

Proc report data=combined nowd;
   columns team mon,(n pctn sum pctsum),y diff_cust Diff_Y  Diff_PCT_cust  Diff_PCT_Y;
   define team/ group mlf format=$type. preloadfmt order=data  'צוות';
   define mon/across order=data  'חודש';

   define diff_cust/ computed;
			   compute diff_cust;
			      diff_cust =_c2_-_c6_;
			   endcomp ;

	define Diff_PCT_cust/ computed;
			   compute Diff_PCT_cust;
			   Diff_PCT_cust=_C3_-_C7_;
			   endcomp ;

   define Diff_Y/ computed;
			   compute Diff_Y;
			      Diff_Y=_C4_-_C8_;
			   endcomp ;

define Diff_PCT_Y/ computed;
	compute Diff_PCT_Y;
	Diff_PCT_Y=_C5_-_C9_;
			   endcomp ;


rbreak after/ summarize;
run;
 





 

 

 

2 REPLIES 2
ballardw
Super User

I want also to ask why  pctn  and pctsum are not in define statements?

Define statements are required when you want to use something other than defaults. Since Pctn and Pctsum are both standard statistics they will have all of the defaults for the statistic just like N and Sum.

 

 

 

ballardw
Super User

See if this helps:

Proc report data=combined nowd;
   columns team mon,(y=yn y=ypctn y=ysum y=ypctsum) diff_cust Diff_Y  Diff_PCT_cust  Diff_PCT_Y;
   define team/ group mlf format=$type. preloadfmt order=data  'צוות';
   define mon/across order=data  'חודש';
   define yn / n 'Customers' ;
   define ypctn /pctn  format=percentn10.2 '% Customers';
   define ysum / sum 'Sales';
   define ypctsum /pctsum format=percentn10.2 '% Sales';
   define diff_cust/ computed;
			   compute diff_cust;
			      diff_cust =_c2_-_c6_;
			   endcomp ;

	define Diff_PCT_cust/ computed;
			   compute Diff_PCT_cust;
			   Diff_PCT_cust=_C3_-_C7_;
			   endcomp ;

   define Diff_Y/ computed;
			   compute Diff_Y;
			      Diff_Y=_C4_-_C8_;
			   endcomp ;

   define Diff_PCT_Y/ computed;
   	compute Diff_PCT_Y;
   	Diff_PCT_Y=_C5_-_C9_;
   			   endcomp ;

rbreak after/ summarize;
run;

Note the creation of "alias" columns from the variable to be analyzed and then the indication of that alias in a define statement with the desired statistic, format and header text.

 

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
  • 2 replies
  • 552 views
  • 0 likes
  • 2 in conversation