BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akosyan
Fluorite | Level 6

Hi All,

 

Can you please help me with the following formatting change ?

 

I have a date column (format yynnm4.    for example 1803 representing 2018 March)

I want to create the exact same column but as text ( for example text 1803, or as an integer 1803).

 

Thanks,

1 ACCEPTED SOLUTION
4 REPLIES 4
ballardw
Super User

Depending on what you mean by "exact same column".

A new variable with the character value can be done with:

data want;
   set have;
   datechar = put(date,yymmn4.);
run;

I believe your description confused the M and N in the format.

 

If you mean to change the existing variable you can't directly. Once a variable is created the type is fixed. You would have to rename your existing variable and create a variable with the same name using similar code:

data want;
   set have (rename=(date=olddate);
   date = put(olddate,yynnm4.);
   drop olddate;
run;
Patrick
Opal | Level 21

Why? It's much better to store dates as SAS Date values and not as strings.

 

You can use a put function with a format to write a numerical value as a string. You then assign the result of this to a new variable of type character.

date_string_var=put(sasdate_var, yymmn4.);
akosyan
Fluorite | Level 6

Thanks all, this worked !!!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 674 views
  • 3 likes
  • 4 in conversation