Reputation: 171
I have the following Dataset:
Date Action
Jan2006 A
Jan2006 A
Jan2006 A
Jan2006 N
Jan2006 N
Feb2006 A
Feb2006 N
Feb2006 N
Mar2006 A
Mar2006 N
Mar2006 N
Apr2006 A
Apr2006 N
and so on until Dec2014.
What I want to do is to make a new dataset so that when it's the beginning of the year (i.e. Jan2006) then I want to keep both A and N, but only N with the remaining months of the year (Feb, March...until Dec). So the dataset above should look like the following:
Date Action
Jan2006 A
Jan2006 A
Jan2006 A
Jan2006 N
Jan2006 N
Feb2006 N
Feb2006 N
Mar2006 N
Mar2006 N
Apr2006 N
and so on until Dec2014.
As you can see, when it's the beginning of the month (Jan), then I am keeping both A and N, but only N with the remaining months until I get to the beginning (Jan) of next year and then the process repeates (i.e. keep A and N when Jan2007, and only N for the remaining months and so on for all the remaining years).
What is the best way to go about doing this? I know I could probably use some sort of conditional if then statement, but I just can't wrap my head around it.
Upvotes: 0
Views: 50
Reputation: 1958
You can use something like..I hope your date is in date format, otherwise substr to fetch for "Jan"
if month(date) ne 1 and Action= "A" then delete;
if not date format then
if substr(date,1,3) ne "Jan" and Action= "A" then delete;
Upvotes: 1