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

/

I am merging two datsets by week starting from 2020106 and ending 20201023. how do i use it in if statement?

data combined;

merge a(in=in1) b(in=in2);

by week_date;

 

if in1 and in2 and week_date >=20201016 and week_date <20201023;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@archita wrote:

/

I am merging two datsets by week starting from 2020106 and ending 20201023. how do i use it in if statement?

data combined;

merge a(in=in1) b(in=in2);

by week_date;

 

if in1 and in2 and week_date >=20201016 and week_date <20201023;

run;


Number values in the range of 20201016 would be past the year 20,000 and outside the range of currently valid SAS dates.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

@archita wrote:

/

I am merging two datsets by week starting from 2020106 and ending 20201023. how do i use it in if statement?

data combined;

merge a(in=in1) b(in=in2);

by week_date;

 

if in1 and in2 and week_date >=20201016 and week_date <20201023;

run;


Did you get an error? If so what?  Or did it not work? If so how do you know?

How is the variable WEEK_DATE defined in each of those two datasets?  Your code is assuming it is a number with values like 20,201,016.  I human might think a number like that could mean the 16th of November of the year 2020.

But if your variable is character then values need quotes.  Such as '20201016'.

And if the variable has date values (you can tell because it will have a date type format attached to, such as the YYMMDDN8. format that would make the values look like the numbers you typed in your code.  In that case you need to use date literals that have values that the DATE informat can interpret.  Such as '16NOV2020'd.

archita
Fluorite | Level 6
Thank you all
andreas_lds
Jade | Level 19

All depends on how the dates are stored in your datasets. If they are not sas-dates, but strings or just numbers, fix that problem before you continue with merging.

Kurt_Bremser
Super User

If that code does not throw an ERROR or a WARNING, but returns zero observations, then it is very likely that you have SAS date values in week_date, which are in the 5-digit range for all current dates.

 

Otherwise, we need to see the log as is for diagnostics. And run a PROC CONTENTS on the dataset and post the result, so we can get an idea about your week_date variable.

ballardw
Super User

@archita wrote:

/

I am merging two datsets by week starting from 2020106 and ending 20201023. how do i use it in if statement?

data combined;

merge a(in=in1) b(in=in2);

by week_date;

 

if in1 and in2 and week_date >=20201016 and week_date <20201023;

run;


Number values in the range of 20201016 would be past the year 20,000 and outside the range of currently valid SAS dates.

 

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

archita
Fluorite | Level 6
Thank you

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 815 views
  • 1 like
  • 5 in conversation