BookmarkSubscribeRSS Feed
Hema_12
Fluorite | Level 6

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

3 REPLIES 3
Kurt_Bremser
Super User

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;
Hema_12
Fluorite | Level 6

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

Kurt_Bremser
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 921 views
  • 0 likes
  • 2 in conversation