BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
indox
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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? 🙂

 

Otherwise, please clarify? 

indox
Obsidian | Level 7

Yes, this is what i want.

Thanks.

PeterClemmensen
Tourmaline | Level 20

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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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