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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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