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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.