DATA Step, Macro, Functions and more

Selecting rows from a dataset to another one with condition

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

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: 734

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

Something like this? Smiley Happy

 

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;

View solution in original post


All Replies
PROC Star
Posts: 734

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? Smiley Happy

 

Otherwise, please clarify? 

Occasional Contributor
Posts: 7

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: 734

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

Something like this? Smiley Happy

 

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.

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

Discussion stats
  • 3 replies
  • 139 views
  • 0 likes
  • 2 in conversation