Hi all, newbie question:
I currently have a huge dataset listing thousands of patients and the dates they've had blood drawn on. I'd like to winnow the list down to just the bloods drawn during the week before last to create a less cumbersome working list for those draws.
I found the Today function while poking around online and figured that I could just use that to grab today's date and calculate an interval from that but it isn't working as expected. My code attempt:
data
data _null_;
tday=today();
proc sql;
create table Bloods_Abridged as select distinct patient_number, date_drawn from Bloods_Complete
where (tday-date_drawn) < 17 and (tday-date_drawn) > 11; quit;
And the resulting error text:
ERROR: The following columns were not found in the contributing tables: tday.
So clearly I'm messing something up in getting the table to recognize 'tday' but I have no idea what. Also not 100% sure if my code for calculating the interval is correct, since the problem with the table not recognizing 'tday' means I don't even get there. The date_drawn column is in mmddyy10 format, would my code for the interval work if the initialization of today's date worked? Trying this on SAS 9.4. Any help is appreciated, thanks!
Because your "data data _null_" statement created a dataset named "data", with 1 var and 1 observation. You never called that dataset in proc sql, and it wouldn't have been very useful anyhow.
Why not use the "today()" function, instead of variable TDAY, inside your proc sql?
Because your "data data _null_" statement created a dataset named "data", with 1 var and 1 observation. You never called that dataset in proc sql, and it wouldn't have been very useful anyhow.
Why not use the "today()" function, instead of variable TDAY, inside your proc sql?
Aaaaaaaand that worked perfectly, thanks! Just deleted the data step and changed the proc step to this:
proc sql;
create table Bloods_Abridged as select distinct patient_number, date_drawn from Bloods_Complete
where (today()-date_drawn) < 17 and (today()-date_drawn) > 11; quit;
And it gave me exactly what I wanted. The weird initial format was from me copying the Today function code straight off the support.sas site thinking I shouldn't mess with it since I pretty much only know enough SAS to break stuff 🙂
Thanks again!
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.