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

Hi all,

 

I am again having trouble with what seems to be a fairly simple task but I am not able to execute it.

In my dataset I have a variable that contains product names. These products can be of different types (let's say 0 and 1200) and depending on the type, they have a different maturity. If they are of type 0, the maturity is equal to the reporting date (that I have available, it's always the same value) and if they are of type 1200, the maturity is equal to the reporting date plus 100 years (I have created this other variable in a data step, it's maturity_1200 in the code that I attach).

My desired output dataset must have the product names, reporting date and maturity date, like:

 

REPORTING_DT     PRODUCT           MATURITY

31/03/2018               bonds_0               31/03/2018

31/03/2018               bonds_1200         31/03/2118

31/03/2018               savings_0            31/03/2018

31/03/2018               savings_1200      31/03/2118

 

I have tried the code that I attach, but it doesn't work. I have tried to find syntax mistakes but the log is just not returning any errors and I get no output. It just doesn't run. I have also tried adding maturity as an empty variable and then updating (it has worked in the past) but again, it doesn't work. 

data work.step3;
   set work.step3;
   maturity=ifn(product like '%_1200', maturity_1200, reporting_dt);
   FORMAT maturity DDMMYY10.;
run;

 Thank you so much for your time and help

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data have;
    input REPORTING_DT   ddmmyy10.  PRODUCT     $12.  ;
cards;
31/03/2018 bonds_0      
31/03/2018 bonds_1200   
31/03/2018 savings_0    
31/03/2018 savings_1200 
;
data want;
    set have;
    if find(product,'1200')>0 then maturity=intnx('year',reporting_dt,100,'s');
    else maturity=reporting_dt;
    format maturity reporting_dt ddmmyy10.;
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
data have;
    input REPORTING_DT   ddmmyy10.  PRODUCT     $12.  ;
cards;
31/03/2018 bonds_0      
31/03/2018 bonds_1200   
31/03/2018 savings_0    
31/03/2018 savings_1200 
;
data want;
    set have;
    if find(product,'1200')>0 then maturity=intnx('year',reporting_dt,100,'s');
    else maturity=reporting_dt;
    format maturity reporting_dt ddmmyy10.;
run;
--
Paige Miller
mariapf
Fluorite | Level 6

Hi Paige, this worked great and I'm sure it will help me a lot with future tasks. Thank you so much!

Reeza
Super User
LIKE doesn't work in a data step. The log should be generating errors and it's helpful if you include those. Try using INDEX or FIND instead of Like. Or a standard IF statement would always work, rather than IFN.

ballardw
Super User

Use of the same data set as input and output as in

data work.step3;
   set work.step3;
   maturity=ifn(product like '%_1200', maturity_1200, reporting_dt);
   FORMAT maturity DDMMYY10.;
run;

completely replaces the data set. So a previous step may have had your data set work.step3 have not observations or done something else that causes the log not to show errors this time but if you had a logic error you are stuck with previous results.

 

While learning coding you really want to create a new output data set.

 

 

mariapf
Fluorite | Level 6

Hi, thank you for your response and thank you for your advice. 

I have tried creating  a new dataset and checking my previous one but the problem still remained. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 755 views
  • 2 likes
  • 4 in conversation