BookmarkSubscribeRSS Feed
Ullsokk
Pyrite | Level 9

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

16 REPLIES 16
novinosrin
Tourmaline | Level 20

Would switching to WORDATE format be a good idea?

 

format sep feb to worddate. ;
novinosrin
Tourmaline | Level 20

Or more closer seems to be WORDDATX format

format sep feb to worddatx. ;

 

 

 

Ullsokk
Pyrite | Level 9
No, I need the month name in norwegian
unison
Lapis Lazuli | Level 10

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.;
-unison
Ullsokk
Pyrite | Level 9
That doesnt fix the issue, but seems to be the problem. The needed length is 18
Tom
Super User Tom
Super User

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
ErikLund_Jensen
Rhodochrosite | Level 12

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;

 

dddn.gif

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Ullsokk
Pyrite | Level 9

That is really strange. Will give that a go if I need to. 

unison
Lapis Lazuli | Level 10

@ErikLund_Jensen : Odd, I'm in SAS UE and running the same code yields:

Screenshot from 2020-01-20 11-07-44.png

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;
-unison
Tom
Super User Tom
Super User

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;

 

Ullsokk
Pyrite | Level 9

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)

 

Tom
Super User Tom
Super User

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
Tom
Super User Tom
Super User

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.

 

ChrisNZ
Tourmaline | Level 20

Not only is the length 17, but a longer length is not accepted on my system.

Bug. Report it to tech support.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 3123 views
  • 1 like
  • 7 in conversation