08-17-2017 10:48 AM
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!
08-17-2017 10:53 AM
Are you sure it's a character? If so, use the yymmdd INFORMAT, NOT the 10 format. INPUT uses the format it currently appears in.
You should create a SAS date, IMO.
input(tc.valid_from, yymmdd8.) < '01Jul2017'd
08-17-2017 10:55 AM - edited 08-17-2017 10:57 AM
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
08-17-2017 11:03 AM
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.
08-17-2017 11:44 AM
It sounds like your existing variable is character, including dashes. For that, try:
input(tc.valid_from, yymmdd10.) < '01Jul2017'd
You need to read 10 characters (not 8).
08-17-2017 01:02 PM
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'
08-17-2017 01:07 PM
@Reeza, I really appreciate your help. This is in fact a character as I state, and the results are all the dates that I expect. Thank you again for your contribution.
08-17-2017 01:20 PM
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;
Need further help from the community? Please ask a new question.