BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Costasg
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Tom
Super User Tom
Super User

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

Altal
Calcite | Level 5

OR this...

data want;

set example;

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

qtr  = input(date1,yyq6.);

format qtr yyq6.;

run;

Jagadishkatam
Amethyst | Level 16

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
Costasg
Calcite | Level 5

Many thanks to everybody!

All solutions work!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1297 views
  • 6 likes
  • 4 in conversation