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?
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;
You say you want data with 2019 but select data below with 2018?
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;
@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.
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!
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.