BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

What is the way to convert SAS date into char value.

for example:

From SAS data value  of 19FEB2019 I want to get following 3 values (in 3 different columns):

1902 (structure YYMM)

19/02 (structure YY/MM)

2019/02 (sructure YYYY/MM)

 

 

/**Convert SAS date into chat YYMM*/
/**Convert SAS date into chat YY-MM*/
/**Convert SAS date into chat YYYY/MM*/
Data new;
sas_date='19Feb2019';
wanted1=put(sas_date,???.);/*wanted char value 1902*/
wanted2=put(sas_date,???.);/*wanted char value 19-02*/
wanted3=put(sas_date,???.);/*wanted char value 2019/02*/
Run;
3 REPLIES 3
Ronein
Meteorite | Level 14
Data new;
sas_date='19Feb2019'd;
wanted1=put(sas_date,yymmd7.);/*YYYY-MM*/
wanted2=put(sas_date,yymmn4.);/*YYMM*/
wanted3=put(sas_date,yymmd9.);/*YYYY-MM*/
Run;

I found the error. 

The sas_date was not date....

Ronein
Meteorite | Level 14

My question:

How to convert SAS date into char with structure  MM/YYYY  ?


How to convert SAS date into char with structure  MM/YY ?

 

 

 

/**Convert SAS date into char */
/**Convert SAS date into char */
/**Convert SAS date into char */
Data new;
sas_date='19Feb2019'd;
wanted1=put(sas_date,yymmd7.);/*YYYY-MM*/
wanted2=put(sas_date,yymmn4.);/*YYMM*/
wanted3=put(sas_date,yymmd9.);/*YYYY-MM*/
wanted4=put(sas_date,???.);/*MM/YYYY*/
wanted5=put(sas_date,???.);/*MM/YY*/
Run;
Kurt_Bremser
Super User

Maxim 1: Read the Documentation. Scroll down to the "Date" category, and you'll find what you're looking for.

 

Big hint: if the year/month format is called YYMM, what would a developer call the format for month/year?

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 794 views
  • 0 likes
  • 2 in conversation