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

Hi,

 

I have the table below, customer_id and the subscription date. I want to add another field showing the Saturday date before the sub date.

 

Your help would be much appreciated.

 

Thank You very much

 

 

Have

   
 

customer_id

sub_table_date

 
 

50095

22-Dec-15

 
 

50206

10-Jan-16

 
 

50220

26-May-16

 
       
       
 

Want

   
 

customer_id

sub_table_date

Saturday_before_dt

 

50095

22-Dec-15

19-Dec-15

 

50206

10-Jan-16

04-Jun-16

 

50220

26-May-16

21-May-16

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

!!Post test data in the form of a datastep!!

Its not hard, and it saves lots of questions!!!

 

 

As such I am guessing dates are dates:

data have;	
  customer_id=50095; sub_table_date="22Dec2015"d;
run;
data want;
  set have;
  sat_date=sub_table_date;
  do while (weekday(sat_date) ne 7);
    sat_date=sat_date-1;
  end;
  format sub_table_date sat_date date9.;
run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

data have;

input customer_id sub_table_date :date9.;

datalines;

50095 22Dec2015

50206 10Jan2016

50220 26May2016

;

 

 data want;

set have;

do _n_=sub_table_date by -1 until(weekday(_n_)=7);

if weekday(_n_)=7 then Saturday_before_dt=_n_;

end;

format sub_table_date Saturday_before_dt date9.;

run;

 

Regards,

Naveen Srinivasan

RW9
Diamond | Level 26 RW9
Diamond | Level 26

!!Post test data in the form of a datastep!!

Its not hard, and it saves lots of questions!!!

 

 

As such I am guessing dates are dates:

data have;	
  customer_id=50095; sub_table_date="22Dec2015"d;
run;
data want;
  set have;
  sat_date=sub_table_date;
  do while (weekday(sat_date) ne 7);
    sat_date=sat_date-1;
  end;
  format sub_table_date sat_date date9.;
run;
Question
Fluorite | Level 6
Thank you very much RW9 and novinosrin. It works well...

##- Please type your reply above this line. Simple formatting, no
attachments. -##
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data Have;
input customer_id$ sub_table_date:date7.;
format sub_table_date date7.;
datalines;
50095 22-Dec-15
50206 10-Jan-16  	
50220 26-May-16
;

data want;
   set have;
   Saturday_before_dt = intnx('week',sub_table_date,-1, 'end');
   format Saturday_before_dt date7.;
run;
Question
Fluorite | Level 6
Thank you Draycut.

##- Please type your reply above this line. Simple formatting, no
attachments. -##

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 2869 views
  • 0 likes
  • 4 in conversation