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

Hi all, facing problem to filter my table. I want the data with year 2018 and less than equal to month 3 only. For Ex,

 

 

ORIGINAL TABLE

fruits                       vegetable                                     year                                  month

kiwi                            carrot                                         2015                                  2

watermelon              eggplant                                      2015                                  10

banana                     cabbage                                     2016                                   1

orange                        chili                                            2017                                 6

apple                           tomato                                     2018                                   1

durian                         potato                                         2018                                 2

mango                        seaweed                                     2018                                  3

 

 

I  want my table to be like this

NEW TABLE

fruits                       vegetable                                     year                                  month

apple                           tomato                                     2018                                   1

durian                         potato                                         2018                                 2

mango                        seaweed                                     2018                                  3

 

 

I have a lot of columns actually, this is only a very simple example. What can I do with this?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. Then simply do

 

data original;
input fruits $ vegetable $ year month;
datalines;
kiwi carrot 2015 2
watermelon eggplant 2015 10
banana cabbage 2016 1
orange chili 2017 6
apple tomato 2018 1
durian potato 2018 2
mango seaweed 2018 3
;

data new;
   set original;
   where year=2018 & month le 3;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

You say you want data with 2019 but select data below with 2018?

Kayla_Tan222
Calcite | Level 5
Ouh, soory its a typo . I want data with 2018
PeterClemmensen
Tourmaline | Level 20

Ok. Then simply do

 

data original;
input fruits $ vegetable $ year month;
datalines;
kiwi carrot 2015 2
watermelon eggplant 2015 10
banana cabbage 2016 1
orange chili 2017 6
apple tomato 2018 1
durian potato 2018 2
mango seaweed 2018 3
;

data new;
   set original;
   where year=2018 & month le 3;
run;
ballardw
Super User

@Kayla_Tan222 may find in useful that dataset options can be applied to a data set where ever a DATA= is used such as

 

proc print data=original (where=(year=2018 and month le 3));
run;

So you do not need to create additional data sets to subset data.

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1079 views
  • 0 likes
  • 3 in conversation