BookmarkSubscribeRSS Feed
mehak
Calcite | Level 5

 

Is there anyway by which i can change date 1 automatically and perform intck fn for all the variables which are present in my data set in a row named as couponexpiry

data _dlass_1;                                                                                                                                              
set _dlass_1.grocery_coupons1;

date1 = '21OCT2017'd ;
date2 = '31MAR2014'd;

no_of_months = intck ('MONTH', date1, date2);
no_of_weeks = intck ('WEEK', date1, date2);
no_of_days = intck ('DAY', date1, date2);
run;

 

9 REPLIES 9
PaigeMiller
Diamond | Level 26

@mehak wrote:

 

Is there anyway by which i can change date 1 automatically and perform intck fn for all the variables which are present in my data set in a row named as couponexpiry


I don't know what this means. Please provide a lot more details. Show us exactly what you want to accomplish, with sample data.

--
Paige Miller
mehak
Calcite | Level 5
usecoupweekseqcarrycoupvalamtspentcouponexpiry
31404215.2820/02/2014
32443021/02/2014
       
3130316.7124/02/2014
32331171.9125/02/2014

 

this is my sample data i want to calculate a field for issuance date,as my coupon is valid for 2 months only .

Patrick
Opal | Level 21

@mehak

Sounds like a use case for the intnx() function. Here the link to the docu:

http://go.documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p10v3sa3i4kfxfn1sovhi5xzxh8n.h...

 

PaigeMiller
Diamond | Level 26

@mehak wrote:
usecoup week seq carry coupval amtspent couponexpiry
3 1 4 0 4 215.28 20/02/2014
3 2 4 4 3 0 21/02/2014
             
3 1 3 0 3 16.71 24/02/2014
3 2 3 3 1 171.91 25/02/2014

 

this is my sample data i want to calculate a field for issuance date,as my coupon is valid for 2 months only .


Okay great, thank you. Now I still don't see how this relates to your original question.

--
Paige Miller
Patrick
Opal | Level 21
@mehak wrote:
usecoup week seq carry coupval amtspent couponexpiry
3 1 4 0 4 215.28 20/02/2014
3 2 4 4 3 0 21/02/2014
             
3 1 3 0 3 16.71 24/02/2014
3 2 3 3 1 171.91 25/02/2014

 

this is my sample data i want to calculate a field for issuance date,as my coupon is valid for 2 months only .


@mehak

You need to start posting better formulated questions. First thing: Post sample data in the form of a working and tested SAS data step which creates such data, post a sample of the desired result, then explain us the logic to be used to get from your Have data to your Want result.

 

Based on what you've posted I can only guess that you're after something like below.

data have;
 infile datalines dlm=' ' truncover;
 input usecoup week seq carry coupval amtspent couponexpiry:ddmmyy10.;
 format couponexpiry ddmmyy10.;
 datalines;
3 1 4 0 4 215.28 20/02/2014
3 2 4 4 3 0 21/02/2014
3 1 3 0 3 16.71 24/02/2014
3 2 3 3 1 171.91 25/02/2014
;
run;

data want;
  set have;
  format issue_date ddmmyy10.;
  issue_date=intnx('month',couponexpiry,-2,'s');
run;

I can understand that it's sometimes hard for a beginner to even formulate the question. But you really need to try to do your bit as much as possible and invest a bit more time in formulating the question as else you're going to annoy people to a degree where you simply won't get answers anymore.

Astounding
PROC Star

This post with the sample data is the most useful information you have provided.  Now add one more column to it, showing what the results should look like after the calculations are made.

 

Sample code is not required.  The posters here will assume that the data set you already posted is named HAVE, and the data set that needs to be created with the extra column added should be named WANT.

 

And check out the suggestion from @Patrick ... it is possible that this does exactly what you want.

 

And stay far away from INTCK until you are very sure of what it does.  Using your formulas, it is easy to come up with sample dates where NO_OF_MONTHS is 1, but NO_OF_WEEKS is 0.

Reeza
Super User

data _dlass_1;
set _dlass_1.grocery_coupons1;

date1 = '21OCT2017'd ; <- DON'T HARDCODE YOUR DATA
date2 = '31MAR2014'd;

no_of_months = intck ('MONTH', date1, date2); <- SWITCH THESE TO USE THE VARIABLES IN YOUR DATA SET, NOT HARDCODED
no_of_weeks = intck ('WEEK', date1, date2);
no_of_days = intck ('DAY', date1, date2);
run; 

mehak
Calcite | Level 5


date1 = '21OCT2017'd ; <- DON'T HARDCODE YOUR DATA

 

*( then what should i write here???????)


no_of_months = intck ('MONTH', date1, date2); <- SWITCH THESE TO USE THE VARIABLES IN YOUR DATA SET, NOT HARDCODED

(how can i switch these var???????????? )

Reeza
Super User

I think this falls under creating new variables in SAS. 

Maybe this helps. 

http://video.sas.com/detail/videos/sas-analytics-u/video/4573023399001/creating-a-new-column-in-sas?...

 

Instead of the hardcoded variables, point to your variable names instead. I don't have your data (don't want it either) so don't know what things are called in your data set. It's not really clear what you're trying to do at all or where/what you're having issues with in the question. I

 

f you want us to take the time to answer your questions, please take the time to detail your questions explaining what you have, what you want and what you've tried so far. Include sample data, as text, AND sample output. 

 

Good Luck. 

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
  • 9 replies
  • 1107 views
  • 4 likes
  • 5 in conversation