DATA Step, Macro, Functions and more

Does Lag function works in SAS University Edition???

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Does Lag function works in SAS University Edition???

[ Edited ]

Hi All,

 

Please find the below code.

 

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;

 

I'm getting below error. Can anyone please help?

 

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?
 
Thanks a lot in advance Smiley Happy

 


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

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

Posted in reply to arunvaibhav

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.

 

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,558

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

[ Edited ]
Posted in reply to arunvaibhav

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 Smiley Happy will implement and check this too 

Thanks Smiley Happy

Solution
‎10-26-2016 04:54 PM
Super User
Posts: 5,500

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

Posted in reply to arunvaibhav

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: 3,752

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

Posted in reply to Astounding

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???

Posted in reply to Astounding

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

 

Thanks Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 274 views
  • 6 likes
  • 4 in conversation