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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 538 views
  • 0 likes
  • 2 in conversation