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.

 

 

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