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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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