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 !!!

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