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?
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.
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;
Thanks Shmuel for responding fast. And nice logic 🙂 will implement and check this too
Thanks 🙂
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.
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.
I just deleted the minus symbol and again retyped it and ran, and it worked.
Thanks 🙂
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.