## Does Lag function works in SAS University Edition???

Solved
Occasional Contributor
Posts: 14

# Does Lag function works in SAS University Edition???

[ Edited ]

Hi All,

DATA clinton_data;
INFILE '/folders/myfolders/Module10/clinton.txt' FIRSTOBS= 3 EXPANDTABS;
INPUT @7 Day 7-9 Mo \$ 10-12 Year 14-17 Approve 24-25 Disapprove 32-33 No_opinion 40-41;
Temp_date = catx(" ",Day,Mo,Year);
Date = input(temp_date,DATE11.);
PUT Date = DATE11.;
FORMAT Date MMDDYY10.;
DROP Day Mo Year temp_date;
RUN;

PROC SORT DATA = clinton_data;
BY Date;

DATA clinton_data1;
SET clinton_data;
FORMAT date MMDDYY10.;
elapsed_time = (Date – (lag(Date)));
difference_approval = (Approve – (lag(Approve)));
RUN;

PROC PRINT DATA = clinton_data1;
RUN;

PROC CORR DATA = clinton_data1;
VAR elapsed_time difference_approval;
RUN;

PROC CORR DATA = clinton_data1;
VAR elapsed_time difference_approval;
RUN;

PROC CORR DATA = clinton_data1;
VAR Approve;

WITH elapsed_time;

RUN;

72 elapsed_time = (Date – (lag(Date)));
___
22
68
73 difference_approval = (Approve – (lag(Approve)));
___
22
68
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |, ||, ~=.

ERROR 68-185: The function – is unknown, or cannot be accessed.

74 RUN;

Any ideas please? I think SAS University edition doesn't support LAG function. But I'm not sure.
If so, any thoughts on why I'm getting this error? any alternative thoughts?

Accepted Solutions
Solution
‎10-26-2016 04:54 PM
Super User
Posts: 6,898

## Re: Does Lag function works in SAS University Edition???

It looks like the editor you are using gives you a symbol that looks like a minus sign, but is really something else.  Just find the right symbol for a minus sign.

All Replies
Posts: 1,848

## Re: Does Lag function works in SAS University Edition???

[ Edited ]

There is no LAG(var) for the first observation in the dataset.

You should code:

if _N_ = 1 then do;

elapsed_time = . ;

difference_approval = . ;

end; else do;

elapsed_time = Date – lag(Date);

difference_approval = Approve – lag(Approve);

end;

Occasional Contributor
Posts: 14

## Re: Does Lag function works in SAS University Edition???

Thanks Shmuel for responding fast. And nice logic will implement and check this too

Thanks

Solution
‎10-26-2016 04:54 PM
Super User
Posts: 6,898

## Re: Does Lag function works in SAS University Edition???

It looks like the editor you are using gives you a symbol that looks like a minus sign, but is really something else.  Just find the right symbol for a minus sign.

SAS Super FREQ
Posts: 4,262

## Re: Does Lag function works in SAS University Edition???

To clarify Astounding's comment: if you cut/paste from Miscrosoft word or even some web pages, you can paste in an en-dash or em-dash, which is an HTML or rich-text character. Delete the "minus sign" and replace it with a regular hyphen character.

Occasional Contributor
Posts: 14

## Re: Does Lag function works in SAS University Edition???

I just deleted the minus symbol and again retyped it and ran, and it worked.

Thanks

☑ This topic is solved.