sas - Using an ARRAY Statement with an Iterative DO Statement -


i'm working on data set (data) has 3 variables (var1, var2, var3) in format need change. variables in special date format (for example purposes, oldfmt1) , need change them regular sas date format using datepart function.

the issue need accomplish in single data step using both loop , array calls datepart function. dim function must used used right in array , must drop index varaible (i) before end datasetp.

then, have apply date9. function these changed variables.

i'm new loops , 1 causing me massive headaches. appreciated.

by saying want use datepart function, implying 3 existing variables stored sas "date-time" values. try this:

data have;   var1 = datetime();   var2 = datetime();   var3 = datetime();   format var1-var3 datetime19.; run;  data want;    set have;    array allvars(*) var1-var3;    i=1 dim(allvars);       allvars(i) = datepart(allvars(i));       end;    format var1-var2 date9.;    drop i; run; 

please remember sas has 2 data types (numeric , character). dates, times, , datetimes "known" such when used appropriate format. in sas:

  • a date number of days since january 1, 1960
  • a time number of seconds since midnight
  • a datetime number of seconds since january 1, 1960.

and notice date9. not function; format. there great many different formats can used "exposed" underlying value of variable value not change. that's 1 of useful features of sas programming.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -