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

Using this code:

 

 

DATA WORK.TestDataSet;
   INPUT Uid Col1 Col2 Target $;
   DATALINES;
	1 5.1 3.5 13.12345
	2 4.9 3.15 2.1345
;

DATA WORK.TestDataSet;
    SET WORK.TestDataSet;
    MSE = (Target - ((Col1 + Col2) + exp(2.345)))**2;
RUN;

proc summary data = WORK.TestDataSet;
 var MSE;
 output out = WORK.ProcSumOut sum=;
run;

proc print data = WORK.ProcSumOut;
run; 

 

I would like to divide the 'computed column' by noobs (the number of rows in WORK.TestDataSet). Is this possible? The result should be in WORK.ProcSumOut.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 Unless you have missing values the average is the sum divided by the number of observations so you can calculate your statistics by specifying the mean option

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16
I think we cannot divide the computed column in the proc summary. However in a new data step it is possible.

First we need to get the n from proc summary into the WORK.ProcSumOut. Then in the new data step we need to divide the sum with n.

proc summary data = WORK.TestDataSet ;
var MSE;
output out = WORK.ProcSumOut n= sum=;
run;

data WORK.ProcSumOut2;
set WORK.ProcSumOut ;
sum2=sum/n;
run;

Hope this is what you are expecting.
Thanks,
Jag
csetzkorn
Lapis Lazuli | Level 10

Sorry but your suggestion does not produce the desired output of 151.104. However, the following code, which makes use of _FREQ_. does the job:

 

DATA WORK.TestDataSet;
   INPUT Uid Col1 Col2 Target $;
   DATALINES;
	1 5.1 3.5 13.12345
	2 4.9 3.15 2.1345
;

DATA WORK.TestDataSet;
    SET WORK.TestDataSet;
    MSE = (Target - ((Col1 + Col2) + exp(2.345)))**2;
RUN;


proc summary data = WORK.TestDataSet ;
	var MSE;
	output out = WORK.ProcSumOut sum=;
run;

proc print data = WORK.ProcSumOut;
run;

data WORK.ProcSumOut2;
	set WORK.ProcSumOut ;
	MSE=MSE/_FREQ_;
run;

proc print data = WORK.ProcSumOut2;
run; 
Reeza
Super User


proc means data = WORK.TestDataSet ;
var MSE;
output out = WORK.ProcSumOut sum= Mean= / autoname;
run;

Reeza
Super User

 Unless you have missing values the average is the sum divided by the number of observations so you can calculate your statistics by specifying the mean option

Astounding
PROC Star

If for some reason you want what you are asking for, it's already there.  The output data set automatically contains _FREQ_.  It is the total number of observations (including those that have missing values, so using it in calculations may not give you the mean exactly).

 

You are specifying that the output data set should contain the SUM.  You can also ask for other statistics, such as MEAN (as Reeza mentioned), N (number of observations with a non-missing value), and NMISS (number of observations with a missing value).

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
  • 2636 views
  • 2 likes
  • 4 in conversation