- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
help?
I'm using proc sql and I'd prefer to stay with it but I'll listen to any suggestions! 🙂
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both. I ended up using this
tc.valid_from < '01JUL2017'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
@serrld113 wrote:
Thank you both. I ended up using this
tc.valid_from < '01JUL2017'
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you again, @Reeza. You've been very helpful.