BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ManitobaMoose
Quartz | Level 8

Hi,

 

I am trying to create a second data set which finds when the day of the VisitD variable  is a monday or the year of the VisitD variable is 2002. I am using the Set function. I am learning from SAS by Example and the answers are not in the book. Could someone offer some assistance? Thanks.

 

Below is the original dat set from which I want to find which dates fall on a Monday or are in the year 2002, using SAS code.

 

Libname SASdata '/folders/myfolders/SASData' ;
Data SasData.HealthHosp ;
    Input PatID 3.
          DOB   mmddyy10.
          VisitD mmddyy10. ;
    format DOB VisitD mmddyy10. ;
Datalines ;
00112/25/19445/17/2000
00205/11/19668/4/2002
00308/03/20009/2/2003
;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this?

 

Data HealthHosp ;
    Input PatID 3.
          DOB   mmddyy10.
          VisitD mmddyy10. ;
    format DOB VisitD mmddyy10. ;
Datalines ;
00112/25/19445/17/2000
00205/11/19668/4/2002
00308/03/20009/2/2003
;

data want;
   set HealthHosp;
   where weekday(VisitD)=2 | year(VisitD)=2002;
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Like this?

 

Data HealthHosp ;
    Input PatID 3.
          DOB   mmddyy10.
          VisitD mmddyy10. ;
    format DOB VisitD mmddyy10. ;
Datalines ;
00112/25/19445/17/2000
00205/11/19668/4/2002
00308/03/20009/2/2003
;

data want;
   set HealthHosp;
   where weekday(VisitD)=2 | year(VisitD)=2002;
run;
novinosrin
Tourmaline | Level 20

data want;
set HealthHosp;
where strip(put(weekday(VisitD),weekdate9.))="Monday" or year(visitd)=2002;
run;

ManitobaMoose
Quartz | Level 8

Grat, thanks. One quick follow up: I thought for the Weekday function Sunday = 1 and Monday = 2? That is what the book says, but maybe that has changed since?

 

Thanks.

Astounding
PROC Star

Good set of tools, but notice ...

 

For Monday, the WEEKDAY function should return 2 not 1.  Also note, if you are reading from the raw data, you can build in efficiency (not a consideration when you have only a few lines of raw data):

 

Data want ;
    Input @ 14 VisitD mmddyy10. @ ;
if weekday(VisitD) = 2 or year(VisitD) = 2002;
Input @ 1 PatID 3. DOB mmddyy10. ; format DOB VisitD mmddyy10. ; Datalines ; 00112/25/19445/17/2000 00205/11/19668/4/2002 00308/03/20009/2/2003 ;

 

Reeza
Super User

 

YEAR/MONTH/DAY functions.

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
  • 6 replies
  • 2236 views
  • 1 like
  • 5 in conversation