input - SAS date formatting -


i have dataset variable, start date, takes lot of different values using character format.

i have split dataset using values in start date column, because want transform date variable 2 new columns 2 different date values:

if length(startvalue) = 6 output  a6; else if length(startvalue) = 8 output a8 ; else if length(startvalue) = 1 output a1; else output a_other; 

one value written this: 090209 (ddmmyy)

i want format variable both date9. format , ddmmyyd10. format this:

format  startvalue2 date9.; format startvalue3 ddmmyyd10.; 

i got work approach in data step:

format  startdato2 date9.; format startdato3 ddmmyyd10.; startdato2 = input(put(startdato,6.),ddmmyy6.); startdato3 = input(put(startdato,6.),ddmmyy6.); 

another value written this: 15-08-17 (dd-mm-yy) want 2 formats on value, this:

format  startvalue2 date9.; format startvalue3 ddmmyyd10.; 

but here cannot use copy of expression above:

format  startvalue2 date9.; format startvalue3 ddmmyyd10.; startvalue2 = input(put(startvalue,8.),ddmmyydw.); startvalue3= input(put(startvalue,8.),ddmmyydw.); 

do know why? , how can value transformed date9. format , ddmmyyd10 format?

kind regards

maria

you not need convert values numeric put statement when using input. input's goal take character input , turn numeric value sas math with. how remember it:

  • input: convert input value into numeric value
  • put: output numeric value character value

a simpler solution can try using anydtdte. informat. capable of reading following informats:

  • date
  • datetime
  • ddmmyy
  • julian
  • mdyampm
  • mmddyy
  • mmxyy
  • monyy
  • time
  • ymddttm
  • yymmdd
  • yyq
  • yyxmm
  • month, day, year

for example:

%let default_datestyle = %sysfunc(getoption(datestyle));  options datestyle=dmy;  data want;     set have;      startdato2  = input(startdato, anydtdte.);     startvalue2 = input(startvalue, anydtdte.);      startdato3  = startdato2;     startvalue3 = startvalue2;      <rest of code>;      format startvalue2 date9.            startvalue3 ddmmyyd10.            startdato2  date9.            startdato3  ddmmyyd10.     ; run;  options datestyle = &default_datestyle; 

give informat try , see if able everything. if not, can account special cases conditional logic.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -