Forecasting using SAS Forecast Server, SAS/ETS, and more

informat year and quarter

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

informat year and quarter

The format of my data is 199201- first quarter of 1992. How do I input it?

data raw;

infile cards;

input var1 ;

cards;

199201;

run;

What should I put after var1? Is there any SAS informat that works?

thanks


Accepted Solutions
Solution
‎09-12-2012 03:59 AM
Regular Contributor
Posts: 151

Re: informat year and quarter

There isn't a standard SAS informat for your data, so one way is to convert the existing data to an informat that SAS can read in.  You will need to read Var1 as character for the SUBSTR function to work.  Basically I'm just inserting a Q after the 4th number, which then puts it in the YYQ7 informat.

data raw;

infile cards;

input var1 $;

var2=input(cat(substr(var1,1,4),'Q',substr(var1,5)),yyq7.);

format var2 date9.;

cards;

199201

;

run;

View solution in original post


All Replies
Solution
‎09-12-2012 03:59 AM
Regular Contributor
Posts: 151

Re: informat year and quarter

There isn't a standard SAS informat for your data, so one way is to convert the existing data to an informat that SAS can read in.  You will need to read Var1 as character for the SUBSTR function to work.  Basically I'm just inserting a Q after the 4th number, which then puts it in the YYQ7 informat.

data raw;

infile cards;

input var1 $;

var2=input(cat(substr(var1,1,4),'Q',substr(var1,5)),yyq7.);

format var2 date9.;

cards;

199201

;

run;

Super User
Super User
Posts: 6,500

Re: informat year and quarter

Or just

substr(var1,5,1)='Q';

Regular Contributor
Posts: 151

Re: informat year and quarter

Good spot Tom, since the leading 0 for the quarter is optional.

Contributor
Posts: 23

Re: informat year and quarter

OK. got it. No SAS informat works for 199301. I can only find yyQ.w informat. Since the original file is excel, I did it by using '&' to combine them.

How can I change the status to 'answered'?

thanks

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 468 views
  • 1 like
  • 3 in conversation