JCP
JCP

Reputation: 19

SAS Variable with mixed values

I have some variables that have date values however, some rows have character information thus making this a character variable. I need to add 90 and also subtract today's date from these variables. Example Variable Variable1 08/30/18 02/27/18 06/30/18 value 05/31/18 pending 08/30/18

I was thinking, if there is a way to change all character values to missing/blank then I would be able to change this character variable to date format and do my calculations.

Please help! Thank you.

Upvotes: 0

Views: 61

Answers (2)

Shuying WEI
Shuying WEI

Reputation: 11

First You can test the syntax using one values. like this

  data _null_;
strdate='08/30/18';
a=input(strdate,mmddyy10.);
cal1=a+90-today();
cal2=put(cal1,mmddyy10.);
put strdate a cal1 cal2;
run;

Then create new variable for store new values, like cal2 above mentioned.

if you don't want to change original variable name, rename cal2 in data step.

Upvotes: 0

data _null_
data _null_

Reputation: 9109

I think you should create a new date variable by "reading" your existing variable.

data mixed;
   input var:$8.;
   date = input(var,??mmddyy10.);
   if not missing(date) then do;
      p90 = date + 90;
      mtoday = date - today();
      end;
   format date p90 mtoday mmddyy10.;
   cards;
08/30/18
02/27/18
06/30/18
value
05/31/18
pending
08/30/18 
;;;;
   run;
proc print;
   run;

Upvotes: 1

Related Questions