Help using Base SAS procedures

Character to Date

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

Character to Date

Hello all,

I am trying to convert a character date but what I am doing doesn't seem to work. I am attaching the file where date is of the form "1993-4" and the format is $6.

I am using this code to convert it to yyq6. but it doesn't work:

data want;

set example;

qtr=input(date,yyq6.);

format qtr yyq6.;

run;

Any suggestions?

Attachment

Accepted Solutions
Solution
‎10-02-2013 09:50 AM
Super User
Super User
Posts: 7,076

Re: Character to Date

data want;

input date $6. ;

qtr=input(translate(date,'Q','-'),yyq6.);

format qtr yyq6.;

put (_all_) (=);

cards;

1993-4

run;

date=1993-4 qtr=1993Q4

View solution in original post


All Replies
Solution
‎10-02-2013 09:50 AM
Super User
Super User
Posts: 7,076

Re: Character to Date

data want;

input date $6. ;

qtr=input(translate(date,'Q','-'),yyq6.);

format qtr yyq6.;

put (_all_) (=);

cards;

1993-4

run;

date=1993-4 qtr=1993Q4

Contributor
Posts: 62

Re: Character to Date

OR this...

data want;

set example;

date1=tranwrd(date, "-", "q");

qtr  = input(date1,yyq6.);

format qtr yyq6.;

run;

Trusted Advisor
Posts: 1,137

Re: Character to Date

Please try the below code,

data have;

    input date $6.;

    new=input((tranwrd(date,'-','q')),yyq6.);

    format new yyq6.;

cards;

1993-4

;

proc print;

run;

Thanks,

Jagadish

Thanks,
Jag
Frequent Contributor
Posts: 75

Re: Character to Date

Many thanks to everybody!

All solutions work!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 479 views
  • 6 likes
  • 4 in conversation