I want to get all the dates that are less than 20170701 but my date format is in yyyy-mm-dd and so it's a character
input(tc.valid_from,10.) < 20170701
this code gives me this error message: "An error occured executing the workspace job "Report1". The server is disconnected." if I comment this section out then the project runs fine.
I'm using proc sql and I'd prefer to stay with it but I'll listen to any suggestions! 🙂
yes, I know it's a character. When I hover over the variable name on the table, there's this little gray "cloud" that describes the variable as such: Type:Character,Length:10,label:Valid_From
your suggested code returns error 22-322 Syntax error and error 76-322 😞
Then you have some other issue that you're not showing, my code is correct assuming your variable is character.
data check; length x $10.; format x $10.; x="20170701"; y = input(x, yymmdd8.); format y date9.; if y < "01Jul2017"d then flag=1; else flag=0; run;
Post your full code AND log.
If this is a character variable as you state, you won't get errors but it won't work as you expect. It's a character comparison, not a numerical comparison.
Thank you both. I ended up using this
tc.valid_from < '01JUL2017'
I'm putting this example for future users. The answer you've marked as correct cannot be correct given what you've stated that the variable is character, so most likely there's something else going on that you haven't stated.
See the sample code below.
*create sample data with format described by OP, date as character in format YYYY-MM-DD and a SAS date variable; data sample; do date='01Jan2017'd to '31Dec2017'd; date_char = put(date, yymmdd10.); output; end; run; proc sql; *Correct answer according to OP; create table wrong as select * from sample where date_char < '01JUL2017'; *Comparison with date variables; create table correct1 as select * from sample where date < '01JUL2017'd; create table correct2 as select * from sample where input(date_char, yymmdd10.) < '01JUL2017'd; quit;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.