简体   繁体   中英

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.

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM