Help using Base SAS procedures

std function

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

std function

Please help. I'm trying to calculate the std deviation of a variable and output as a new variable.

used: sales_dev = std(sales);

got this error message;

 

ERROR 71-185: The STD function call does not have enough arguments.

 

Thanks


Accepted Solutions
Solution
‎01-20-2016 11:54 AM
Super User
Posts: 17,963

Re: std function

Since SAS processes data row by row, thats not quite how it works. The STD() function in a data step is intended to compute the STD of a set of values in the same row.

Proc means is the way to calculate it for a column.

Proc means data=sashelp.class;
Var weight;
Output out=want;
Run;

To get it merged back into the data step merge it back in.

You can also use SQL where the function behaves as expected but SQL does not and will merge it in directly 😀 You do get a note in the log which many places frown upon.

Proc sql;
Create table want2 as
Select *, std(weight) as std_var
From sashelp.class;
Quit;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,131

Re: std function

std function requires atleast two variables, since you mentioned only one it is giving this error. Also i believe you are using this std in data step, if you have only one variable then please use group by statement
Thanks,
Jag
Solution
‎01-20-2016 11:54 AM
Super User
Posts: 17,963

Re: std function

Since SAS processes data row by row, thats not quite how it works. The STD() function in a data step is intended to compute the STD of a set of values in the same row.

Proc means is the way to calculate it for a column.

Proc means data=sashelp.class;
Var weight;
Output out=want;
Run;

To get it merged back into the data step merge it back in.

You can also use SQL where the function behaves as expected but SQL does not and will merge it in directly 😀 You do get a note in the log which many places frown upon.

Proc sql;
Create table want2 as
Select *, std(weight) as std_var
From sashelp.class;
Quit;
Super User
Posts: 17,963

Re: std function

If you want to calculate the std for specific groups, add them into a GROUP BY clause.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1066 views
  • 4 likes
  • 3 in conversation