BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6
Hi, I have a dataset A: 20110405 20120604 20130806 20140603 20150607 20160705 I want the data B from 20130806 to 20150607 only can I do this in SAS? thanks
7 REPLIES 7
japelin
Rhodochrosite | Level 12

 

I don't know what kind of data you have, but is this what you mean?

data have;
  input dt:yymmdd8.;
  format dt yymmdd8.;
datalines;
20110405
20120604
20130806
20140603
20150607
20160705
;
run;

data want;
  set have;
  if '06AUG2013'd <= dt <= '07JUN2015'd;
run;
Smitha9
Fluorite | Level 6
I do not want any format for the date . Dataset: ID Date 1 20110405 2 20120604 3 20130806 4 20140603 5 20150607 6 20160705 I want ID from 3 to 5 thanks
kelxxx
Quartz | Level 8
data want;
set have;
if 3 <= ID <= 5;
run;
japelin
Rhodochrosite | Level 12

Provide the correct data and structure before asking questions.

Do you want to filter by ID or by date, and are the values like date character values or numeric values?

Smitha9
Fluorite | Level 6
Hi, I have a dataset A: 20110405 20120604 20130806 20140603 20150607 20160705 I want the data B from 20130806 to 20150607 only. Can I do this in SAS? thanks
PaigeMiller
Diamond | Level 26
data have;
    input date :yymmdd8. @@;
    format date yymmdd10.;
    cards;
20110405 20120604 20130806 20140603 20150607 20160705
;
data want;
    set have;
    if date>='08JUN2013'd and date<='06JUL2015'd;
run;
--
Paige Miller
kelxxx
Quartz | Level 8

 

/*if type of variable date = numeric */
data have;
input date ;
cards;
20110405
20120604
20130806
20140603
20150607
20160705
;run;

data want;
set have;
if  20130806 <= date <= 20150607;
run;

/*if type of variable date = character */
data have;
input date $ ;
cards;
20110405
20120604
20130806
20140603
20150607
20160705
;run;

data want;
set have;
if  '20130806' <= date <= '20150607';
run;

/*if type of variable date = date sas */
data have;
input date yymmdd8. ;
cards;
20110405
20120604
20130806
20140603
20150607
20160705
;run;

data want;
set have;
if '06AUG2013'd <= date <= '07JUN2015'd;
run;

 

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