Solved
New Contributor
Posts: 2

# Converting character yyyy-q to numeric yyqd.

[ Edited ]

Hey guys,

I have a pipe-delimited text file that I'm trying to import to a SAS table and the formatting is not going particularly well.

I have a column labeled "QRTR" which is essentially in this format: "2014-2".  This value represents the 2nd quarter of 2014.

Is there a way for me to convert this charvar to a numeric with an INPUT statement, and then convert the numeric to its' correct format using yyqd.?

Thank you,

Sean

Accepted Solutions
Solution
‎05-18-2017 09:07 AM
Super User
Posts: 13,293

## Re: Converting character yyyy-q to numeric yyqd.

```data example;
x = "2014-2";
date= input(translate(x,'Q','-'),yyq6.);
format date yyq6.;
run;
```

The resulting date acutally is assumed to be the first day the calendar quarter. You can use date9. or other format to examine it if needed.

All Replies
Super User
Posts: 23,237

## Re: Converting character yyyy-q to numeric yyqd.

Read it in as character, replace - with Q and convert using ANYDTDTE informat.

``````data test;
informat date \$8.;
input date \$;
y = input(translate(date, "Q", "-"), anydtdte.);
format y yyqd.;
cards;
2012-3
2013-1
2014-2
2015-5
2016-1
;
run;``````
Solution
‎05-18-2017 09:07 AM
Super User
Posts: 13,293

## Re: Converting character yyyy-q to numeric yyqd.

```data example;
x = "2014-2";
date= input(translate(x,'Q','-'),yyq6.);
format date yyq6.;
run;
```

The resulting date acutally is assumed to be the first day the calendar quarter. You can use date9. or other format to examine it if needed.

New Contributor
Posts: 2

## Re: Converting character yyyy-q to numeric yyqd.

Thank you both!  I added in your code to my data step and it worked beautifully.

Posts: 1,309

## Re: Converting character yyyy-q to numeric yyqd.

Then mark a solution
☑ This topic is solved.