@doofst wrote:
I have created a sas data named tables.Q3 from an excel file containing hundreds of thousands of observations.
I would like to now extract specific observations that satisfy one condition in 1 variable and another condition in the other and print those data sets.
I first sorted the data set by one variable using:
PROC SORT DATA=tables.Q3 OUT=tables.Q4;
BY start_position;
RUN;
this produced a sas data set that sorted the start_code (which is a numeric) variable.
I want to now print from the dataset tables.Q4 a table that will only include those observations that satisfy start_position=5000 and variable 2 (which is a datetime variable in the form of DDMMMYYY HH:MM:SS) as one specific date (i.e 20OCT17).
Thanks in advance for the help.
Are selecting by the datetime? or just want to display the datetime as a date in that format?
Compare the code snippet you say generated an error:
831 where start_position=6008 and variable_2=:'30APR17';
ERROR: WHERE clause operator requires compatible variables.
832 run;
with @Astounding's suggestion:
where start_position=5000 and datepart(variable_2) = '20oct2017'd;
DATE literals are quoted values ind date7 or date9 appearance followed by a D to tell SAS this intended to be used as a date literal. Without the D it is treated a simple character value and generates the error comparing numeric to character.
The function DATEPART tells SAS to only use the Date portion of a datetime value. The =: is right out as you want the date literal numeric version.