The following seems to work for all but dates in september, which truncates the last digit of the year.
data datotest;
sep= "15SEP2019"d;
feb= "15FEB2019"d;
to = today();
format sep feb to NORDFWDX. ;
run;
This gives me 15. september 201, not 15. september 2019. For shorter month names, it works.
Any help would be much appreciated
Would switching to WORDATE format be a good idea?
format sep feb to worddate. ;
Or more closer seems to be WORDDATX format
format sep feb to worddatx. ;
The NORDFWDX format can be displayed from length 3-17 (https://www.mwsug.org/proceedings/2008/saspres/MWSUG-2008-SAS07.pdf). I'd suggest changing to:
format sep feb to NORDFWDX17.;
Sounds like a bug. Report it to SAS.
The format needs to use a width of 18 to display
1234+678901234+67890 15. september 2019
But the maximum width that it allows is 17.
If you use a width of 16 it will abbreviate the month name and then it has room for the full year value.
666 data _null_; 667 sep= "15SEP2019"d; 668 feb= "15FEB2019"d; 669 jan= "15JAN2019"d; 670 put (sep feb jan) (=/NORDFWDX17.) ; 671 put (sep feb jan) (=/NORDFWDX16.) ; 672 run; sep=15. september 201 feb=15. februar 2019 jan=15. januar 2019 sep=15. sep. 2019 feb=15. feb. 2019 jan=15. jan. 2019
Hi @Ullsokk
Here is a comparison that supports the theory of a bug. There is no reason why the DANDFWDX format should behave differently from the NORDFWDX format (except for the spelling of december). The format EURDFWDX might work with your locale settings, it gives the same as DANDFWDX in my setup:
data datotest (drop=i);
format dd DANDFWDX. dn NORDFWDX. de EURDFWDX.;
do i = 1 to 12;
dd = mdy(i,15,2019);
dn = dd;
de = dd;
output;
end;
run;
That is really strange. Will give that a go if I need to.
@ErikLund_Jensen : Odd, I'm in SAS UE and running the same code yields:
Maybe a versioning difference?
@Ullsokk , perhaps a custom picture format is the fix?
proc format;
picture custnord (default=18) low-high='%0d. %B %Y' (datatype=date language=norwegian);
run;
data test;
format dn custnord.;
do dn = '01JAN2019'd to today();
output;
end;
run;
The picture format looks like a winner.
Use
'%d. %B %Y'
to match how the format handles single digit day of the month values.
You will need to use something a different picture format if you also want to support shorter widths like the system function can.
proc format;
picture custnord (default=18 max=18)
low-high='%d. %B %Y' (datatype=date language=norwegian)
;
picture custnord_short (default=13 max=13)
low-high='%d. %b. %Y' (datatype=date language=norwegian)
;
run;
data test;
do month=1 to 12;
do day=1,15;
date=mdy(month,day,2019);
custom1=put(date,custnord18.);
nordic1=put(date,nordfwdx17.); /* Cannot use w=18 if using single byte encoding */
match1=left(custom1)=left(nordic1);
custom2=put(date,custnord_short13.);
nordic2=put(date,nordfwdx13.);
match2=left(custom2)=left(nordic2);
output;
format date yymmdd10.;
end;end;
run;
proc print;
where not match1 or not match2;
run;
I had to implement this fix:
tmp=put(&from.,NORDFWDX.);
from = tranwrd(tmp,'201','2019');
Nasty code, and won't work for 2020, but it works for my case (which is to export to csv)
Build the string yourself. The NORDFMN format generates the full names.
data check;
do month=1 to 12 ;
date=mdy(month,15,2019);
length nord1 nord2 $18;
nord1 = put(date,nordfwdx.-L);
nord2 = catx(' ',put(date,day2.)||'.',put(date,NORDFMN.),year(date));
output;
format date yymmdd10.;
end;
run;
proc print;
where nord1 ne nord2;
run;
Obs month date nord1 nord2 9 9 2019-09-15 15. september 201 15. september 2019
Note that the format works when running SAS using Unicode support instead of using single byte encoding. I think is because it change the max width for the format from 17 to 34 and the default width from 17 to 34.
Not only is the length 17, but a longer length is not accepted on my system.
Bug. Report it to tech support.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.