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
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.