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

I have a variable called qy that looks like:

 

2008 Q1

2008 Q1

2009 Q2

2009 Q2

2009 Q3

2009 Q4

2009 Q4

2009 Q4

 

How can I set it in proper SAS format?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Ok. Do like this then

 

data have;
input qy $&;
datalines;
2008 Q1
2008 Q1
2009 Q2
2009 Q2
2009 Q3
2009 Q4
2009 Q4
2009 Q4
;

data want;
    set have;
    dt=input(compress(qy), yyq7.);
    format dt date9.;
run;

 

Result:

 

qy      dt
2008 Q1 01JAN2008
2008 Q1 01JAN2008
2009 Q2 01APR2009
2009 Q2 01APR2009
2009 Q3 01JUL2009
2009 Q4 01OCT2009
2009 Q4 01OCT2009
2009 Q4 01OCT2009

 

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

What do you consider a 'proper' SAS format?

 

Also, is this a character variable?

adrfinance
Obsidian | Level 7

How do I view whether it is a character variable?

PeterClemmensen
Tourmaline | Level 20

in the "Alphabetic List of Variables and Attributes" section of the output from 

 

proc contents data=YourDataSetHere;
run;
PeterClemmensen
Tourmaline | Level 20

Ok. Do like this then

 

data have;
input qy $&;
datalines;
2008 Q1
2008 Q1
2009 Q2
2009 Q2
2009 Q3
2009 Q4
2009 Q4
2009 Q4
;

data want;
    set have;
    dt=input(compress(qy), yyq7.);
    format dt date9.;
run;

 

Result:

 

qy      dt
2008 Q1 01JAN2008
2008 Q1 01JAN2008
2009 Q2 01APR2009
2009 Q2 01APR2009
2009 Q3 01JUL2009
2009 Q4 01OCT2009
2009 Q4 01OCT2009
2009 Q4 01OCT2009

 

adrfinance
Obsidian | Level 7

My initial dataset has over 8000 rows but when I run your code it gets reduced to only 10 rows.. Why is this the case? How can I fix it?

ballardw
Super User

@adrfinance wrote:

My initial dataset has over 8000 rows but when I run your code it gets reduced to only 10 rows.. Why is this the case? How can I fix it?


Copy the code with the messages from the LOG. Paste into a code box opened on the forum using the {I} icon.

 

Why? Need code and info that will be in the log.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3092 views
  • 0 likes
  • 3 in conversation