## Selecting rows from a dataset to another one with condition

Solved
Occasional Contributor
Posts: 12

# Selecting rows from a dataset to another one with condition

Hello,

I have a data set called dates containing multiple date variables. I created variables d1 to d54 containing these date variables' years.

I woul like to get the id and the "d" variable if the year is not equal to 2017.

I don't know if i'm clear enough.

Thank for help.

Accepted Solutions
Solution
‎03-30-2017 05:54 AM
PROC Star
Posts: 1,401

## Re: Selecting rows from a dataset to another one with condition

Something like this?

``````data have;
input ID d1 d2 d3 d4;
datalines;
1 2016 2017 2013 2011
2 2014 2013 2010 2009
3 2013 2011 2017 2008
4 2015 2015 2007 2008
5 2017 2008 2007 2013
;

data want;
set have;
array years[*] d1-d4;

do i = 1 to dim(years);
if years[i] = 2017 then output;
end;

run;``````

All Replies
PROC Star
Posts: 1,401

## Re: Selecting rows from a dataset to another one with condition

If I understand you correctly, you want a subset of your dataset named dates, that contains the ID and your 'd' variable if neither one of the 54 year variables are equal to 2017?

Occasional Contributor
Posts: 12

## Re: Selecting rows from a dataset to another one with condition

Yes, this is what i want.

Thanks.

Solution
‎03-30-2017 05:54 AM
PROC Star
Posts: 1,401

## Re: Selecting rows from a dataset to another one with condition

Something like this?

``````data have;
input ID d1 d2 d3 d4;
datalines;
1 2016 2017 2013 2011
2 2014 2013 2010 2009
3 2013 2011 2017 2008
4 2015 2015 2007 2008
5 2017 2008 2007 2013
;

data want;
set have;
array years[*] d1-d4;

do i = 1 to dim(years);
if years[i] = 2017 then output;
end;

run;``````
☑ This topic is solved.