I am trying to understand the following code and had a trouble finding the meaning for both _link and _temp.
%if %lowcase(&id)=cusip %then %do;
proc sql;
create view _link
as select permno, ncusip,
min(namedt) as fdate format=date9., max(nameendt) as ldate format=date9.
from crsp.dsenames
group by permno, ncusip;
create table _temp
as select distinct b.permno, a.*
from &inset a left join _link b
on a.cusip=b.ncusip and b.fdate<=a.&evtdate<=b.ldate
order by b.permno, a.&evtdate;
quit;%end;
%else %do;
/*pre-sort the input dataset in case it is not sorted yet*/
proc sort data=&inset out=_temp;
by permno &evtdate; /* error correction. CHANGE HERE */
run;
%end;
I looked for _link in multiple sources(language reference, step by step programming with base SAS, and google), but I could not find information about it. I would appreciate if you can share where to look for the definition and syntax of _link and _temp.
Thank you very much.
Basically in this case they are the names of the resulting data view or data set. SAS names for data sets start with a letter or _ character and have a maximum lenght of 32 characters consisting of letter, digit or _ character.
_link may well have been named "lookup" "Linkset" "fred". Thats just what the coder chose as the name indicates it may be used in some sort of linking operation.
_temp would indicate a data set the coder considers to be temporary but different then a possibly existing set named "temp"
Basically in this case they are the names of the resulting data view or data set. SAS names for data sets start with a letter or _ character and have a maximum lenght of 32 characters consisting of letter, digit or _ character.
_link may well have been named "lookup" "Linkset" "fred". Thats just what the coder chose as the name indicates it may be used in some sort of linking operation.
_temp would indicate a data set the coder considers to be temporary but different then a possibly existing set named "temp"
Haha, usually I get ashamed when I ask a question. But for this one, I feel especially ashamed even after getting the answer. Since we have link statement, I thought _link has some special function!
Thank you for your comment and I will never forget that name in SAS can start with _.
That's why formatting one's code properly is so important: it boosts legibility and reduces chances of errors.
You wouldn't have asked the question if the programmer had taken a few seconds to write:
create view _LINK
as select PERMNO
, NCUSIP
, min(NAMEDT) as FDATE format=date9.
, max(NAMEENDT) as LDATE format=date9.
from CRSP.DSENAMES
group by PERMNO, NCUSIP
Just using vertical alignment and lower/uppercase for sas language/user names makes the code so much easier to develop and maintain.
Thank you ChrisNZ!
That is so true. I recently started learning SAS, and your advice can definitely save hours of debugging and coding for me. I will definitely keep code as you have shown me 🙂
Also, 'underbar' is the swedish word for 'Wonderful' 🙂
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.