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;
@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.
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 .
Sounds like a use case for the intnx() function. Here the link to the docu:
@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.
@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 .
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.
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.
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;
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???????????? )
I think this falls under creating new variables in SAS.
Maybe this helps.
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.
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.
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.