Help using Base SAS procedures

how to transfer string to date?

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

how to transfer string to date?

Hi,

I get string variable like this,  2001-12

I'd like to transfer this variable into date format like yyyymm;

How should I deal with this?

THX!


Accepted Solutions
Solution
‎12-29-2011 03:44 AM
Super User
Posts: 9,681

how to transfer string to date?

data want;
input a $;
date=input(cats(a,'-01'),yymmdd12.);
format date yymmn6.;
cards;
2011-12
2002-1
;
run;

Ksharp

View solution in original post


All Replies
Solution
‎12-29-2011 03:44 AM
Super User
Posts: 9,681

how to transfer string to date?

data want;
input a $;
date=input(cats(a,'-01'),yymmdd12.);
format date yymmn6.;
cards;
2011-12
2002-1
;
run;

Ksharp

Contributor
Posts: 60

how to transfer string to date?

THX!

Valued Guide
Posts: 2,175

how to transfer string to date?

if your string is not being read with input statements, then use the formula that Ksharp suggests above. However, when you are reading that string with an INPUT statement, immediately it can be converted to the date standard with informat ANYDTDTE.

Borrowing from Ksharp's demo above,

data want;

  input  date anydtdte7. ;

  format date yymmn6.;

list; cards;

2011-12

2002-1

;

run;

Contributor
Posts: 60

how to transfer string to date?

THX!

I get it.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 2601 views
  • 3 likes
  • 3 in conversation