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;
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;
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.