SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

compare 2 date values in YYYY.WK format

Reply
Contributor
Posts: 41

compare 2 date values in YYYY.WK format

Hi,

I want compare 2 date values available in year.week format. Is there is any way to compare 2 date which one is bigger.

 

Call_week   Dcall_week

2014.01     2014.02

2016.11     2016.10

2015.18     2015.20

 

Thanks.

 

Regards,

Rajesh

Super User
Posts: 17,963

Re: compare 2 date values in YYYY.WK format

Are the dates SAS dates, ie numeric with a date format?

Contributor
Posts: 41

Re: compare 2 date values in YYYY.WK format

Yes. Both are Numaric and best7. format

Super User
Posts: 17,963

Re: compare 2 date values in YYYY.WK format

BEST7 is not a date format, yyyy.wk would be a date format.

 

Regardless, since the years/weeks are in chronological order you can compare the values directly. 

 

In general, it's best to create a SAS date to do comparisons. 

 

 

Contributor
Posts: 41

Re: compare 2 date values in YYYY.WK format

Sorry for the inconveniecne. Below is the format.

 

Call_week      Dcall_week

2014.01         02.2014

2016.11         10.2016.

2015.18         20.2015

 

 

If it is possible to compare these two columns, could you please share the logic?

Super Contributor
Posts: 305

Re: compare 2 date values in YYYY.WK format

Hello,

 

If your variables are numeric (as you mentioned in a previous post) than you compare them as comparing 2 numbers:

 

e.g. if Call_week gt Dcall_week then new_var=Call_week;

 

If your variables are character you transform them into numeric variables using input function and the appropriate informat.

Here you can find the SAS INFORMATS BY CATEGORY

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001239776.htm

Afterwards the comparison will also resume to number comparing.

Super User
Super User
Posts: 7,430

Re: compare 2 date values in YYYY.WK format

Post some example data from your dataset - as a datastep so we can read it in directly as it is in your dataset.  The reason is 02.2014 is not best7. format, it is either text or a Z type format.  Also post what you want the output to look like, what do you mean compare?  Difference in days/weeks/years, same month - its not clear from your post.

 

Super User
Posts: 17,963

Re: compare 2 date values in YYYY.WK format


chirumalla wrote:

Sorry for the inconveniecne. Below is the format.

 

Call_week      Dcall_week

2014.01         02.2014

2016.11         10.2016.

2015.18         20.2015

 

 

If it is possible to compare these two columns, could you please share the logic?


This is not the same as your original post and inconsistent with your answer regarding the variable type and format. Please confirm your data structure and variable types, preferably by posting the output from proc contents. 

Ask a Question
Discussion stats
  • 7 replies
  • 352 views
  • 0 likes
  • 4 in conversation