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

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 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
Shmuel
Garnet | Level 18

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; 

arunvaibhav
Obsidian | Level 7

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

Thanks 🙂

Astounding
PROC Star

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.

 

 

Rick_SAS
SAS Super FREQ

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.

arunvaibhav
Obsidian | Level 7

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

 

Thanks 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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