- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).
Here is the code I have at the moment
PROC SORT DATA = HAVE;
BY DATE ;
RUN;
DATA HAVE;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF DATE = 2013Q4 THEN DELETE;
RUN;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATA want;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF put(DATE, YYQ6.) = "2013Q4" THEN DELETE;
if year(date) = 2013 and qtr(date) = 4 then delete;
RUN;
FYI - do not use this style of programming. It's harder to debug and find any issues in your programming, instead give your output data set a unique name as above otherwise you cannot trace your work between steps.
DATA HAVE;
SET HAVE;
@pbhatt wrote:
I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).
Here is the code I have at the moment
PROC SORT DATA = HAVE;
BY DATE ;
RUN;
DATA HAVE;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF DATE = 2013Q4 THEN DELETE;RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATA want;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF put(DATE, YYQ6.) = "2013Q4" THEN DELETE;
if year(date) = 2013 and qtr(date) = 4 then delete;
RUN;
FYI - do not use this style of programming. It's harder to debug and find any issues in your programming, instead give your output data set a unique name as above otherwise you cannot trace your work between steps.
DATA HAVE;
SET HAVE;
@pbhatt wrote:
I would like to delete the first n-obs or rows based on the date, but I am unsure how. The DATE variable is numeric and FORMAT IS YYQ6 (ex. 2013Q1).
Here is the code I have at the moment
PROC SORT DATA = HAVE;
BY DATE ;
RUN;
DATA HAVE;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF DATE = 2013Q4 THEN DELETE;RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DATA WORK.TEST1;
SET HAVE;
IF VAR1 = 0 THEN DELETE;
IF DISCHARGE < '01OCT2013'D THEN DELETE;
RUN;
Also, thanks again Reeza for the tips. I will make sure to use better syntax so I can trace my steps/mistakes and troubleshoot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your code technically works but it deletes anything prior to Q4, not just in the third quarter which is what your original code was trying to do.
Only you know which one is right, as this isn't a technical question.
You can simplify it slightly if desired as well.
DATA WORK.TEST1;
SET HAVE;
IF VAR1 = 0 or DISCHARGE < '01OCT2013'D THEN DELETE;
RUN;