- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a column in a data set that is
Type = Numeric
Length = 8
Format = MONYY7.
So the entries appear like FEB2021
APR2020
NOV2020
MAR2021
and so forth. How can I convert this data to
February 2021
April 2020
November 2020
March 2021
Thank you for assistance.
wklierman
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So currently have date values (number of days since 1960) and are using the MONYY format to display them. You could use the WORDDATE format, but that will include the day of the month. Note also that will by default right align the values.
proc print data=have;
format datevar worddate.;
run;
There is also the NLDATE format that will produce similar values. That is left aligned but it also adjusts the strings to match your language settings.
If you really want to not print the day of the month then you will probably need to make your own format. Or create a new character variable to store that information.
data test;
length month datevar datevar2 8 datestr1 datestr2 $18;
do month=1 to 12;
datevar=mdy(month,1,2021);
datevar2=datevar;
datestr1=put(datevar,worddate18.-L);
datestr2=catx(' ',scan(datestr1,1),scan(datestr1,-1));
format datevar monyy7. datevar2 worddate.;
output;
end;
run;
Obs month datevar datevar2 datestr1 datestr2 1 1 JAN2021 January 1, 2021 January 1, 2021 January 2021 2 2 FEB2021 February 1, 2021 February 1, 2021 February 2021 3 3 MAR2021 March 1, 2021 March 1, 2021 March 2021 4 4 APR2021 April 1, 2021 April 1, 2021 April 2021 5 5 MAY2021 May 1, 2021 May 1, 2021 May 2021 6 6 JUN2021 June 1, 2021 June 1, 2021 June 2021 7 7 JUL2021 July 1, 2021 July 1, 2021 July 2021 8 8 AUG2021 August 1, 2021 August 1, 2021 August 2021 9 9 SEP2021 September 1, 2021 September 1, 2021 September 2021 10 10 OCT2021 October 1, 2021 October 1, 2021 October 2021 11 11 NOV2021 November 1, 2021 November 1, 2021 November 2021 12 12 DEC2021 December 1, 2021 December 1, 2021 December 2021
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
The closest you can come is with the NLDATEw. format.
NLDATEw. is similar to DATEw. and WORDDATEw., except that NLDATEw. is locale-specific.
Locale-specific means this:
options locale=English_UnitedStates;
data test;
day=15760;
put day nldate.;
run;
versus (for example)
options locale=German_Germany;
data test;
day=15760;
put day nldate.;
run;
You can also make your own format of course with PROC FORMAT!
Koen
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
is your variable a SAS date?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DEC2020
and so on
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Just make a new variable.
data lab;
set bios511.rawlab;
newdate=strip(put(labdate,monname10.))||''||put(year(labdate),4.);
keep labdate newdate;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So currently have date values (number of days since 1960) and are using the MONYY format to display them. You could use the WORDDATE format, but that will include the day of the month. Note also that will by default right align the values.
proc print data=have;
format datevar worddate.;
run;
There is also the NLDATE format that will produce similar values. That is left aligned but it also adjusts the strings to match your language settings.
If you really want to not print the day of the month then you will probably need to make your own format. Or create a new character variable to store that information.
data test;
length month datevar datevar2 8 datestr1 datestr2 $18;
do month=1 to 12;
datevar=mdy(month,1,2021);
datevar2=datevar;
datestr1=put(datevar,worddate18.-L);
datestr2=catx(' ',scan(datestr1,1),scan(datestr1,-1));
format datevar monyy7. datevar2 worddate.;
output;
end;
run;
Obs month datevar datevar2 datestr1 datestr2 1 1 JAN2021 January 1, 2021 January 1, 2021 January 2021 2 2 FEB2021 February 1, 2021 February 1, 2021 February 2021 3 3 MAR2021 March 1, 2021 March 1, 2021 March 2021 4 4 APR2021 April 1, 2021 April 1, 2021 April 2021 5 5 MAY2021 May 1, 2021 May 1, 2021 May 2021 6 6 JUN2021 June 1, 2021 June 1, 2021 June 2021 7 7 JUL2021 July 1, 2021 July 1, 2021 July 2021 8 8 AUG2021 August 1, 2021 August 1, 2021 August 2021 9 9 SEP2021 September 1, 2021 September 1, 2021 September 2021 10 10 OCT2021 October 1, 2021 October 1, 2021 October 2021 11 11 NOV2021 November 1, 2021 November 1, 2021 November 2021 12 12 DEC2021 December 1, 2021 December 1, 2021 December 2021
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There is no specific format, however you can create your own format or use monname. format and year function.
data have;
length dat $20.;
test_date=today();
format test_date monyy7.;
dat=upcase(put(test_date,monname.)||" "||put(year(test_date),4.));
run;
proc print data=have; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
haha I just posted the same code!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the coding approach.
I appreciate your help.
wklierman