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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 577 views
  • 0 likes
  • 3 in conversation