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

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! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
serrld113
Obsidian | Level 7

Thank you both. I ended up using this 

tc.valid_from < '01JUL2017'

View solution in original post

9 REPLIES 9
Reeza
Super User

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 
serrld113
Obsidian | Level 7

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 😞

Reeza
Super User

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.

Astounding
PROC Star

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).

serrld113
Obsidian | Level 7

Thank you both. I ended up using this 

tc.valid_from < '01JUL2017'
Reeza
Super User

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'

 

 

serrld113
Obsidian | Level 7

@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. 

Reeza
Super User

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;
serrld113
Obsidian | Level 7

Thank you again, @Reeza. You've been very helpful.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 11632 views
  • 0 likes
  • 3 in conversation