BookmarkSubscribeRSS Feed
chirumalla
Calcite | Level 5

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

7 REPLIES 7
Reeza
Super User

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

chirumalla
Calcite | Level 5

Yes. Both are Numaric and best7. format

Reeza
Super User

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. 

 

 

chirumalla
Calcite | Level 5

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?

Loko
Barite | Level 11

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

Reeza
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1141 views
  • 0 likes
  • 4 in conversation