DATA Step, Macro, Functions and more

How do I drop observations if one date variable is greater than another date variable?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

How do I drop observations if one date variable is greater than another date variable?

Hello,

 

As indicated in the subject I have 2 date variables A (format: 12DEC2012) and B (format: 20110908) in my data file. I use SAS 9.4 and the following codes, but it always shows A and B are uninitialized. I checked some information from the internet but still do not quite understand how to solve it. Is there anyone can help me figure out the problem?

 

Codes I use:

data abcd.survey;

if A<B then delete;

run;

 

Thanks!


Accepted Solutions
Solution
‎06-21-2016 10:02 PM
Super User
Posts: 6,927

Re: How do I drop observations if one date variable is greater than another date variable?

As @AskoLötjönen stated, you have no data source in your data step, so A and B are not populated.

You probably want

data abcd.survey;
set abcd.survey;
if A < B then delete;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Contributor
Posts: 44

Re: How do I drop observations if one date variable is greater than another date variable?

[ Edited ]

You are missing set-clause, therefore all of your variables are uninitialized.

 

 

Solution
‎06-21-2016 10:02 PM
Super User
Posts: 6,927

Re: How do I drop observations if one date variable is greater than another date variable?

As @AskoLötjönen stated, you have no data source in your data step, so A and B are not populated.

You probably want

data abcd.survey;
set abcd.survey;
if A < B then delete;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,458

Re: How do I drop observations if one date variable is greater than another date variable?

@Therain, I am going to  assume you are relatively new to using SAS. You want to be careful with the word "format" as it has a very specific meaning related to value display. Neither of the values you showed are formats. If the variables are SAS date valued variables then the formats respectively would be Date9. and YYMMDD8. Please confirm by running Proc Contents on the data set that the varibles are date values with formats shown above or is A character and B simply numeric (possibly format Best8. 8.0 or similar) or character.

 

 

Occasional Contributor
Posts: 17

Re: How do I drop observations if one date variable is greater than another date variable?

Thank you! That works very well. Yes, I am a new user of SAS and thanks for the explanation.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 309 views
  • 0 likes
  • 4 in conversation