BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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
Onyx | Level 15
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
Onyx | Level 15

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?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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