Hi All,
I have attached SAS Data Set, New_Gold needs to calculate as
If _n_ then .
if _n_=2 then (Obs2-Obs1)^2
if _n_=3 then (obs3-obs2)^2
if _n_=4 then (Obs4-Obs3)^2 etc
As a first step I am using Lag function.
New_Gold=Lag(1_GoldS)
I am getting the follwing error, Please advise.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE,
GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
ERROR 72-185: The LAG function call has too many arguments.
Seems like you could get what you want with:
new_gold = dif(GoldS)**2;
It will generate a missing value on the first observation, but that is expected.
If you are stuck on using LAG instead of DIF:
new_gold = lag(GoldS);
if _n_=1 then new_gold=.;
else new_gold = (GoldS - new_gold)**2;
Note that SAS uses ** (not ^) to indicate raising to a power.
Good luck.
Hi All,
I have data as attached. New_Gold needs to calculate as
If _n_ then .
if _n_=2 then (Obs2-Obs1)^2
if _n_=3 then (obs3-obs2)^2
if _n_=4 then (Obs4-Obs3)^2 etc
As a first step I am using Lag function.
New_Gold=Lag(1_GoldS)
I am getting the follwing error, Please advise.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE,
GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.
ERROR 72-185: The LAG function call has too many arguments.
Thanks Reeza for your quick reply, I got it.
Seems like you could get what you want with:
new_gold = dif(GoldS)**2;
It will generate a missing value on the first observation, but that is expected.
If you are stuck on using LAG instead of DIF:
new_gold = lag(GoldS);
if _n_=1 then new_gold=.;
else new_gold = (GoldS - new_gold)**2;
Note that SAS uses ** (not ^) to indicate raising to a power.
Good luck.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.