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
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;
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;
Or just
substr(var1,5,1)='Q';
Good spot Tom, since the leading 0 for the quarter is optional.
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.