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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.