BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
econfkw
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Keith
Obsidian | Level 7

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

4 REPLIES 4
Keith
Obsidian | Level 7

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;

Tom
Super User Tom
Super User

Or just

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

Keith
Obsidian | Level 7

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

econfkw
Calcite | Level 5

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

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