BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
schlepro
Fluorite | Level 6

Hi SAS helpers!

Very new to SAS. Using SAS University Edition. Tried searching and kept finding documents about PROC MEANS and similar. What I want to do is perform operations on a column, such as subtracting the mean. What I was expecting was vectorized arithmetic. What I got was something else.

 

proc import datafile='/folders/myfolders/mean_dev_example.xlsx' 
     out = mean_dev
     dbms = xlsx
     replace;
run;

* Subtract mean from RowPlusNoise so it looks like md_RPN;
* This is a variation on what I tried;
data mean_dev;
     set mean_dev;
     md2_RPN = RowPlusNoise - mean(RowPlusNoise);
proc print mean_dev;
run;

What I get is a column of zeros? This should be straight forward. I just don't know what I'm doing. Please assist!

 

Rgds.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Then you need post it at IML forum and Calling @Rick_SAS 

 

Or you could try SQL.

 

 

proc sql;
create table want as
select RowPlusNoise - mean(RowPlusNoise) as md2_RPN
from mean_dev ;
quit;

View solution in original post

3 REPLIES 3
Ksharp
Super User

Then you need post it at IML forum and Calling @Rick_SAS 

 

Or you could try SQL.

 

 

proc sql;
create table want as
select RowPlusNoise - mean(RowPlusNoise) as md2_RPN
from mean_dev ;
quit;
PGStats
Opal | Level 21

There is proc stdize for this specific purpose:

 

data have;
input row	rowplusnoise;
datalines;
1 1.479076657
2 2.295673384
3 3.36174835
4 4.430062053
5 5.592595732
6 6.056510293
7 7.119216833
8 8.510822811
9 9.410188941
10 10.74169849
;

proc stdize data=have out=want method=mean oprefix=o_ sprefix=centered_;
var rowplusnoise;
run;

proc print data=want; run;
Obs. 	row 	o_rowplusnoise 	centered_rowplusnoise
1 	1 	1.4791 	-4.42068
2 	2 	2.2957 	-3.60409
3 	3 	3.3617 	-2.53801
4 	4 	4.4301 	-1.46970
5 	5 	5.5926 	-0.30716
6 	6 	6.0565 	0.15675
7 	7 	7.1192 	1.21946
8 	8 	8.5108 	2.61106
9 	9 	9.4102 	3.51043
10 	10 	10.7417 	4.84194
PG
Rick_SAS
SAS Super FREQ

As KSharp indicated, if you prefer working with vectorized operations, you can use PROC IML, which is included as part of SAS UE.

Here are  a few tips to get started learning the SAS/IML language.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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