BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

Could you please guide me with the 'case when....' statement or other equivalents in order to align in expression in DI Studio for the following if clauses? I was advised not to use user written transformation. Objective is to create a new variable 'PODVER'

 

 

data have;
input renewal_date $ KNKATD;
datalines;
15jun 1
21sep 2
19sep 7
08jan 7
;
run;

data want (drop=current_date);
set have;
current_date=today();
format current_date date9.;
format new_renewal_date date9.;
if (input(cats(renewal_date,"2018"),date9.)<current_date) then new_renewal_date=input(cats(renewal_date,"2019"),date9.);
else new_renewal_date=input(cats(renewal_date,"2018"),date9.);
run;

data want_new;
set want;
format PODVER date9.;
if new_renewal_date='19sep2018'd and KNKATD=7 then PODVER=new_renewal_date+365;
else PODVER=new_renewal_date;
run;

 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just going by the if statments, something like this should work:

case when renewal_date="19sep" then "19sep2019"d
     when input(cats(renewal_date,"2018"),date9.) < today() then input(cats(renewal_date,"2018"),date9.)
     else input(cats(renewal_date,"2019"),date9.) end 

 Its quite hard to tell however, as you use today() in a comparison which will obviously change from day to day, not sure what bearing that has on the code

Babloo
Rhodochrosite | Level 12

You've not checked the condition for KNKATD=7.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Add it in then, you can copy paste directly the and.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 672 views
  • 0 likes
  • 2 in conversation