Desktop productivity for business analysts and programmers

need to convert fiinnish date to date9. format

Reply
New Contributor
Posts: 2

need to convert fiinnish date to date9. format

i have written this sample code i need to convert this finnish date into date9. format. because when i run actual code trough putty it retrieve the finnish date from server and getting issue while comparing with sysdate9.   

 

options mprint mlogic symbolgen;
/*options locale=English_unitedstates;*/
%macro tt;

data one;
a=%sysfunc(strip('30. heinäkuuta 2018 09:52:06'));
call symputx('a',a);
run;
%put &a;
/*%let d=%length(&a);*/
/*%put &d;*/
%let b=%sysfunc(strip(%sysfunc(substr(&a,1,(%length(&a)-8)))));
%put &b;

%LET date_d9=%sysfunc(inputn(&b.,nldate10.),date9.);
%put y=&date_d9.;
%mend;
%tt;

********************************************

log-->

MLOGIC(TT): Beginning execution.
MPRINT(TT): data one;
MPRINT(TT): a='30. heinäkuuta 2018 09:52:06';
MPRINT(TT): call symputx('a',a);
MPRINT(TT): run;

NOTE: The data set WORK.ONE has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

MLOGIC(TT): %PUT &a
SYMBOLGEN: Macro variable A resolves to 30. heinäkuuta 2018 09:52:06
30. heinäkuuta 2018 09:52:06
2 The SAS System 12:43 Wednesday, August 1, 2018

MLOGIC(TT): %LET (variable name is B)
SYMBOLGEN: Macro variable A resolves to 30. heinäkuuta 2018 09:52:06
SYMBOLGEN: Macro variable A resolves to 30. heinäkuuta 2018 09:52:06
MLOGIC(TT): %PUT &b
SYMBOLGEN: Macro variable B resolves to 30. heinäkuuta 2018
30. heinäkuuta 2018
MLOGIC(TT): %LET (variable name is DATE_D9)
SYMBOLGEN: Macro variable B resolves to 30. heinäkuuta 2018
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set
to a missing value.
MLOGIC(TT): %PUT y=&date_d9.
SYMBOLGEN: Macro variable DATE_D9 resolves to .
y=.
MLOGIC(TT): Ending execution.
42
43 GOPTIONS NOACCESSIBLE;
44 %LET _CLIENTTASKLABEL=;
45 %LET _CLIENTPROCESSFLOWNAME=;
46 %LET _CLIENTPROJECTPATH=;
47 %LET _CLIENTPROJECTNAME=;
48 %LET _SASPROGRAMFILE=;
49
50 ;*';*";*/;quit;run;
51 ODS _ALL_ CLOSE;
52
53
54 QUIT; RUN;
55

Super User
Posts: 10,570

Re: need to convert fiinnish date to date9. format

You're out-complicating yourself. Use a sufficient length for the informat, and Bob's your uncle:

options locale=Finnish_Finland;
data one;
a='30. heinäkuuta 2018 09:52:06';
b=strip(substr(a,1,(length(a)-8)));
c=input(b,nldate20.);
format c yymmddd10.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 2

Re: need to convert fiinnish date to date9. format

Posted in reply to KurtBremser

Hi Krut,

 

I have tried the same code which you have sent but still not getting the date in ddmmyy/date9. format.

it gives missing value

Super User
Posts: 10,570

Re: need to convert fiinnish date to date9. format

Just use the wanted format:

options locale=Fi_Fi;

data one;
a='30. heinäkuuta 2018 09:52:06';
b=strip(substr(a,1,(length(a)-8)));
c=input(b,nldate20.);
d=c;
format c yymmddd10. d date9.;
run;

proc print data=one noobs;
run;

Result:

             a                           b                      c            d

30. heinäkuuta 2018 09:52:06    30. heinäkuuta 2018    2018-07-30    30JUL2018

Which format you use, or if any format at all, depends on what you want to do later on. If you need the date later on for reference in a where or similar, a format is not needed:

data one;
a='30. heinäkuuta 2018 09:52:06';
b=strip(substr(a,1,(length(a)-8)));
c=input(b,nldate20.);
call symput('c',put(c,best.));
run;

%put c=&c.;

data have; /* build some example data */
format date yymmddd10.;
do date = today() - 10 to today() + 10;
  output;
end;
run;

data want; /* select from example */
set have;
where date le &c.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 3 replies
  • 67 views
  • 0 likes
  • 2 in conversation