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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1121 views
  • 1 like
  • 3 in conversation