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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

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?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sentientcarbon
Calcite | Level 5

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!

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1137 views
  • 0 likes
  • 2 in conversation