DATA Step, Macro, Functions and more

Converting character yyyy-q to numeric yyqd.

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

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: 11,343

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.

 

View solution in original post


All Replies
Super User
Posts: 19,780

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: 11,343

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.

Trusted Advisor
Posts: 1,019

Re: Converting character yyyy-q to numeric yyqd.

Then mark a solution
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 346 views
  • 1 like
  • 4 in conversation