BookmarkSubscribeRSS Feed
Jyuen204
Obsidian | Level 7

I am having a problem tring to modify a column of data. I am trying to convert the values of the month field to a Character (FEB2023, MAR2023, APR2023)

 

MONTH
202302
202303
202304

3 REPLIES 3
Tom
Super User Tom
Super User

@Jyuen204 wrote:

I am having a problem tring to modify a column of data. I am trying to convert the values of the month field to a Character (FEB2023, MAR2023, APR2023)

 

MONTH
202302
202303
202304


What is the TYPE of the current MONTH variable?   Run PROC CONTENTS on it.

 

What TYPE to you want for the NEW variable?  To you want to make a character variable with strings like 'FEB2003'?  Or you do want a numeric variable with values like '01FEB2003'd that are formatted to print as FEB2003?

 

If it is already character then what is its storage length?  If it is only $6 then you cannot put 7 characters into it, so you will need to either make a new variable or set the length before referencing the old dataset.

 

If it is numeric what (if any) FORMAT specification is attached to it?

 

If MONTH is numeric with the YYMMN6. format attached then change the format to MONYY7. instead.  You could do that without creating a new dataset by using PROC DATASETS to change the format that is attached.

 

If MONTH is numeric without any special format attached then you don't have dates, just number like 202,302 that only look to humans like they might be dates in yyy,ymm format.  So first convert the number into an actual string and then convert it to a date.  

date = input(put(month,z6.),yymmn6.);

You can then either attach the MONYY7. format to the new numeric variable. Or use the PUT() function to generate a character variable.

 

If MONTH is character you can so the same thing, only skip the initial PUT() since you already have a digit string that the INPUT() function can use.

 

 

Jyuen204
Obsidian | Level 7
it is a date value in that field. I think i finally worked wround a solution.

input(MONTH, yymmn6.) as MONTH format-monyy7.

This gave me the desired output.
Thank you Tom for your input!
Tom
Super User Tom
Super User

@Jyuen204 wrote:
it is a date value in that field. I think i finally worked wround a solution.

input(MONTH, yymmn6.) as MONTH format-monyy7.

This gave me the desired output.
Thank you Tom for your input!

If that worked then you did NOT have a date value.  In fact you did not even have a numeric variable.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 423 views
  • 0 likes
  • 2 in conversation