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

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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